cobia/
cape_array_object_vec.rs

1use crate::C;
2use crate::*;
3
4/// Base implementation for CapeArrayStringVec and CapeArrayValueVec
5
6#[allow(private_bounds)]
7#[derive (Clone)]
8pub struct CapeArrayObjectVec<ElementImpl,ElementInterface> {
9	vec: Vec<ElementImpl>,
10	interface_vec: Vec<ElementInterface>,
11	interface_ptr_vec: Vec<*mut ElementInterface>,
12}
13
14#[allow(private_bounds)]
15impl<ElementImpl,ElementInterface> CapeArrayObjectVec<ElementImpl,ElementInterface> {
16
17	/// Create a new CapeArrayObjectVec
18	///
19	/// Creates a new CapeArrayObjectVec with an empty array.
20	///
21	/// # Examples
22	///
23	/// ```
24	/// use cobia;
25	/// use cobia::prelude::*;
26	/// let arr = cobia::CapeArrayStringVec::new();
27	/// assert_eq!(arr.as_string_vec().len(), 0);
28	/// ```
29	pub fn new() -> Self {
30		Self {
31			vec: Vec::new(),
32			interface_vec: Vec::new(),
33			interface_ptr_vec: Vec::new(),
34		}
35	}
36
37	/// Return a vector
38	///
39	/// Returns a reference to the vector of ElementImpl.
40	///
41	/// # Example
42	///
43	/// ```
44	/// use cobia;
45	/// use cobia::prelude::*;
46	/// let arr = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
47	/// assert_eq!(arr.as_vec()[0].as_string(), "idealGasEnthalpy".to_string());
48	/// ```
49
50	pub fn as_vec(&self) -> &Vec<ElementImpl> {
51		&self.vec
52	}
53
54	///Return size 
55	///
56	///Returns the size of the vector.
57	///
58	/// # Example
59	///
60	/// ```
61	/// use cobia;
62	/// use cobia::prelude::*;
63	/// let arr = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
64	/// assert_eq!(arr.size(), 2);
65	/// ```
66	pub fn size(&self) -> usize {
67		self.vec.len()
68	}
69
70	/// Check if empty
71	///
72	/// Returns true if the vector is empty.
73	///
74	/// # Example
75	///
76	/// ```
77	/// use cobia;
78	/// use cobia::prelude::*;
79	/// let arr = cobia::CapeArrayStringVec::new();
80	/// assert!(arr.is_empty());
81	/// ```
82	pub fn is_empty(&self) -> bool {
83		self.vec.is_empty()
84	}	
85
86	/// Return an iterator for the array.
87	///
88	/// # Examples
89	///
90	/// ```
91	/// use cobia::*;
92	///
93	/// fn test_iter(a: &CapeArrayStringIn) {
94	///		let mut iter = a.iter();
95	///		assert_eq!(cobia::CapeStringConstNoCase::from_string("IDEALGASENTHALPY"),iter.next().unwrap());
96	///		assert_eq!(cobia::CapeStringConstNoCase::from_string("idealgasentropy"),iter.next().unwrap());
97	///		assert!(!iter.next().is_some());
98	/// }
99	/// 
100	/// let arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy", "idealGasEntropy"]);
101	/// test_iter(&CapeArrayStringInFromProvider::from(&arr).as_cape_array_string_in());
102	/// ```
103
104	pub fn iter(&self) -> CapeArrayObjectRefIterator<'_,ElementImpl> {
105		CapeArrayObjectRefIterator {
106			data: &self.vec.as_slice(),
107			index: 0
108		}
109	}
110
111}
112
113/// An iterator that takes a reference to the data in CapeArrayObjectVec
114///
115/// This struct is created by the iter method on CapeArrayObjectVec as well as by the IntoInterator trait on &CapeArrayObjectVec
116///
117/// # Examples
118///
119/// ```
120/// use cobia::*;
121///
122/// fn test_iter(a: &CapeArrayStringIn) {
123///		let mut iter = a.iter();
124///		assert_eq!(cobia::CapeStringConstNoCase::from_string("IDEALGASENTHALPY"),iter.next().unwrap());
125///		assert_eq!(cobia::CapeStringConstNoCase::from_string("idealgasentropy"),iter.next().unwrap());
126///		assert!(!iter.next().is_some());
127/// }
128/// 
129/// let arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy", "idealGasEntropy"]);
130/// test_iter(&CapeArrayStringInFromProvider::from(&arr).as_cape_array_string_in());
131/// ```
132
133pub struct CapeArrayObjectRefIterator<'a, ElementImpl> {
134	pub(crate) data: &'a[ElementImpl],
135	pub(crate) index: usize
136}
137
138impl<'a, ElementImpl> Iterator for CapeArrayObjectRefIterator<'a, ElementImpl> {
139	type Item = &'a ElementImpl;
140	fn next(&mut self) -> Option<Self::Item> {
141		if self.index < self.data.len() {
142			let res = &self.data[self.index];
143			self.index += 1;
144			Some(res)
145		} else {
146			None
147		}
148	}
149}
150
151impl<ElementImpl,ElementInterface> std::ops::Index<usize> for CapeArrayObjectVec<ElementImpl,ElementInterface> {
152	type Output = ElementImpl;
153
154	/// Indexing
155	///
156	/// Returns a reference to the element at the given index.
157	///
158	/// # Arguments
159	///
160	/// * `index` - The index of the element to be returned
161	///
162	/// # Examples
163	///
164	/// ```
165	/// use cobia;
166	/// let arr = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
167	/// assert_eq!(arr[0].as_string(), "idealGasEnthalpy");
168	/// ```
169
170	fn index(&self, index: usize) -> &Self::Output {
171		&self.vec[index]
172	}
173}
174
175impl<ElementImpl,ElementInterface> std::ops::IndexMut<usize> for CapeArrayObjectVec<ElementImpl,ElementInterface> {
176	/// Indexing
177	///
178	/// Returns a mutable reference to the element at the given index.
179	///
180	/// # Arguments
181	///
182	/// * `index` - The index of the element to be returned
183	///
184	/// # Examples
185	///
186	/// ```
187	/// use cobia;
188	/// let mut arr = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
189	/// arr[0].set_string("idealGasHeatCapacity");
190	/// assert_eq!(arr.as_string_vec(), vec!["idealGasHeatCapacity".to_string(), "idealGasEntropy".to_string()]);
191	/// ```
192
193	fn index_mut(&mut self, index: usize) -> &mut Self::Output {
194		&mut self.vec[index]
195	}
196}
197
198/// Vector based CapeArrayStringOut implementation
199///
200/// ICapeArrayString is passed as data container between CAPE-OPEN functions. 
201/// It is up to the caller to provide the interface, and its implementation. 
202/// This class provides a default impementation using a `Vec<CapeStringImpl>`.
203///
204/// # Examples
205///
206/// ```
207/// use cobia::*;
208///
209/// fn set_content(a: &mut CapeArrayStringOut) {
210///     a.put_array(&["idealGasEnthalpy", "idealGasEntropy"]).unwrap();
211/// }
212/// 
213/// let mut arr = cobia::CapeArrayStringVec::new();
214/// set_content(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
215/// assert_eq!(arr.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
216/// ```
217pub type CapeArrayStringVec = CapeArrayObjectVec<CapeStringImpl,C::ICapeString>;
218
219
220impl CapeArrayStringVec {
221
222	/// Initialize from string vector
223	///
224	/// Creates a new CapeArrayStringVec from a vector of array of strings.
225	///
226	/// # Arguments
227	///
228	/// * `array` - A vector or array or slice of strings or string slices to be converted to a CapeArrayStringVec
229	///
230	/// # Examples
231	///
232	/// ```
233	/// use cobia;
234	/// let arr = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
235	/// assert_eq!(arr.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
236	/// ```
237	pub fn from_slice<T: AsRef<str>>(array: &[T]) -> CapeArrayStringVec {
238		let mut vec = Vec::new();
239		let mut interface_vec = Vec::new();
240		let mut interface_ptr_vec = Vec::new();
241		vec .reserve(array.len());
242		interface_vec.reserve(array.len());
243		interface_ptr_vec.reserve(array.len());
244		for s in array.iter() {
245			vec.push(CapeStringImpl::from_string(s.as_ref()));
246			interface_vec.push(vec.last_mut().unwrap().as_cape_string_out());
247			interface_ptr_vec.push((interface_vec.last().unwrap() as *const C::ICapeString).cast_mut());
248		}
249		Self {
250			vec: vec,
251			interface_vec,
252			interface_ptr_vec,
253		}
254	}
255
256	/// Return a string vector
257	///
258	/// Returns a vector of strings from the CapeArrayStringVec.
259	///
260	/// Note that this operation comes with an overhead of string conversion.
261	///
262	/// # Examples
263	///
264	/// ```
265	/// use cobia;
266	/// let arr = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
267	/// let strvec = arr.as_string_vec();
268	/// assert_eq!(strvec, vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
269	/// ```
270	pub fn as_string_vec(&self) -> Vec<String> {
271		let mut vec = Vec::new();
272		vec.reserve(self.vec.len());
273		for s in self.vec.iter() {
274			vec.push(s.as_string());
275		}
276		vec
277	}
278
279	/// Resize
280	///
281	/// Change the size of the vector.
282	///
283	/// # Arguments
284	///
285	/// * `size` - The new size of the vector
286	///
287	/// # Example
288	///
289	/// ```
290	/// use cobia;
291	/// use cobia::prelude::*;
292	/// let mut arr = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
293	/// arr.resize(3);
294	/// assert_eq!(arr.size(), 3);
295	/// ```
296	pub fn resize(&mut self, size: usize) {
297		let old_size = self.vec.len();
298		let size = size as usize;
299		if size < old_size {
300			self.vec.truncate(size);
301			self.interface_vec.truncate(size);
302			self.interface_ptr_vec.truncate(size);
303		} else {
304			self.vec.reserve((size - old_size) as usize);
305			for _ in old_size..size {
306				self.vec.push(CapeStringImpl::new());
307				self.interface_vec.push(self.vec.last_mut().unwrap().as_cape_string_out());
308			}
309			//vector may have been re-allocated, redo interfaces
310			self.interface_ptr_vec.resize(size, std::ptr::null_mut());
311			for i in old_size..size {
312				self.interface_vec[i]=self.vec[i].as_cape_string_out();
313				self.interface_ptr_vec[i]=(&self.interface_vec[i] as *const C::ICapeString).cast_mut();
314			}
315		}
316	}
317
318	/// Set the content of the string array from any object that implements CapeArrayStringProviderIn.
319	///
320	/// # Arguments
321	/// * `array` - An object that implements CapeArrayStringProviderIn
322	///
323	/// # Example
324	///
325	/// ```
326	/// use cobia;
327	///
328	/// let mut arr = cobia::CapeArrayStringVec::new();
329	/// let arr1 = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
330	/// arr.set(&arr1);
331	/// assert_eq!(arr.as_string_vec(), ["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]); //the values have been stored on the object that implements ICapeArrayString
332	/// ```
333	pub fn set<T:CapeArrayStringProviderIn>(&mut self,array:&T) -> Result<(), COBIAError> {
334		let mut string_array_in_from_provider = CapeArrayStringInFromProvider::from(array);
335		let string_array=string_array_in_from_provider.as_cape_array_string_in();
336		self.resize(string_array.size());
337		for i in 0..string_array.size() {
338			self.vec[i].set(&string_array.at(i)?);
339		}
340		Ok(())
341	}
342
343	///interface member
344
345	extern "C" fn get(
346		me: *mut ::std::os::raw::c_void,
347		data: *mut *mut *mut C::ICapeString,
348		size: *mut C::CapeSize,
349	) {
350		let p = me as *mut Self;
351		let str_arr: &mut Self = unsafe { &mut *p };
352		unsafe {
353			*data = str_arr.interface_ptr_vec.as_ptr() as *mut *mut C::ICapeString;
354			*size = str_arr.interface_vec.len() as C::CapeSize;
355		}
356	}
357
358	///interface member
359
360	extern "C" fn setsize(
361		me: *mut ::std::os::raw::c_void,
362		size: C::CapeSize,
363		data: *mut *mut *mut C::ICapeString,
364	) -> C::CapeResult {
365		let p = me as *mut Self;
366		let str_arr: &mut Self = unsafe { &mut *p };
367		str_arr.resize(size as usize);
368		unsafe {
369			*data = str_arr.interface_ptr_vec.as_ptr() as *mut *mut C::ICapeString;
370		}
371		COBIAERR_NOERROR
372	}
373
374	///interface v-table
375
376	const CAPE_ARRAY_STRING_VTABLE: C::ICapeArrayString_VTable = C::ICapeArrayString_VTable {
377		get: Some(Self::get),
378		setsize: Some(Self::setsize),
379	};
380
381}
382
383impl<T: AsRef<str>,const N: usize> From<&[T;N]> for CapeArrayStringVec {
384	/// Creates a new CapeArrayStringVec from reference to a slice of strings.
385	///
386	/// # Arguments
387	///
388	/// * `array` - A slice of strings or string slices to be converted to a CapeArrayStringVec
389	///
390	/// # Examples
391	///
392	/// ```
393	/// use cobia;
394	/// let arr = cobia::CapeArrayStringVec::from(&["idealGasEnthalpy", "idealGasEntropy"]); 
395	/// assert_eq!(arr.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
396	/// ```
397
398	fn from(array: &[T; N]) -> CapeArrayStringVec {
399		CapeArrayStringVec::from_slice(array)
400	}
401}
402
403impl<T: AsRef<str>> From<&[T]> for CapeArrayStringVec {
404	/// Creates a new CapeArrayStringVec from reference to a slice of strings.
405	///
406	/// # Arguments
407	///
408	/// * `array` - A slice of strings or string slices to be converted to a CapeArrayStringVec
409	///
410	/// # Examples
411	///
412	/// ```
413	/// use cobia;
414	/// let arr = cobia::CapeArrayStringVec::from(&["idealGasEnthalpy", "idealGasEntropy"]); 
415	/// assert_eq!(arr.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
416	/// ```
417
418	fn from(array: &[T]) -> CapeArrayStringVec {
419		CapeArrayStringVec::from_slice(array)
420	}
421}
422
423impl<T: CapeArrayStringProviderIn> PartialEq<T> for CapeArrayStringVec {
424	/// Partial equality
425	///
426	/// Checks if the content of the CapeArrayStringVec is equal to the content of another object that implements CapeArrayStringProviderIn.
427	///
428	/// # Arguments
429	///
430	/// * `other` - An object that implements CapeArrayStringProviderIn
431	///
432	/// # Examples
433	///
434	/// ```
435	/// use cobia::*;
436	/// let arr1 = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
437	/// let arr2 = cobia::CapeArrayStringVec::from_slice(&["idealGasEnthalpy", "idealGasEntropy"]);
438	/// let arr3 = cobia::CapeArrayStringVec::from_slice(&["IdealGasEnthalpy", "IdealGasEntropy"]);
439	/// assert!(arr1 == arr2);
440	/// assert!(arr1 != arr3);
441	/// ```
442	fn eq(&self, other: &T) -> bool {
443		let mut provider=CapeArrayStringInFromProvider::from(other);
444		let other=provider.as_cape_array_string_in(); 
445		if self.size() != other.size() {
446			return false;
447		}
448		//compare the string vectors
449		for (i, s) in self.vec.iter().enumerate() {
450			match other.at(i) {
451				Ok(s_other) => {
452					if s != &s_other {
453						return false;
454					}
455				},
456				Err(_) => return false, //if we cannot get the string, they are not equal
457			}
458		}
459		true
460	}
461}
462
463impl CapeArrayStringProviderIn for CapeArrayStringVec {
464	/// Convert to ICapeArrayString
465	///
466	/// Returns a reference to the ICapeArrayString interface.
467	///
468	/// # Examples
469	///
470	/// ```
471	/// use cobia::*;
472	/// use cobia::prelude::*;
473	/// let arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy", "idealGasEntropy"]);
474	///	let i_cape_array_string=arr.as_cape_array_string_in();
475	///	let mut i_cape_array_string_ptr=(&i_cape_array_string as *const C::ICapeArrayString).cast_mut(); //normally a pointer to the interface is received
476	///	let sa = cobia::CapeArrayStringIn::new(&mut i_cape_array_string_ptr); //CapeArrayStringIn from *mut C::ICapeArrayString
477	/// assert_eq!(sa.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
478	/// ```
479
480	fn as_cape_array_string_in(&self) -> C::ICapeArrayString {
481		C::ICapeArrayString {
482			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
483			vTbl: (&Self::CAPE_ARRAY_STRING_VTABLE as *const C::ICapeArrayString_VTable).cast_mut(),
484		}
485	}
486}
487
488impl CapeArrayStringProviderOut for CapeArrayStringVec {
489	/// Convert to ICapeArrayString
490	///
491	/// Returns a mutable reference to the ICapeArrayString interface.
492	///
493	/// # Examples
494	///
495	/// ```
496	/// use cobia::*;
497	/// use cobia::prelude::*;
498	/// let mut arr = cobia::CapeArrayStringVec::from(&["idealGasEnthalpy", "idealGasEntropy"]);
499	///	let i_cape_array_string=arr.as_cape_array_string_out();
500	///	let mut i_cape_array_string_ptr=(&i_cape_array_string as *const C::ICapeArrayString).cast_mut(); //normally a pointer to the interface is received
501	///	let a = cobia::CapeArrayStringOut::new(&mut i_cape_array_string_ptr); //CapeArrayStringOut from *mut C::ICapeArrayString
502	/// assert_eq!(a.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
503	/// ```
504
505	fn as_cape_array_string_out(&mut self) -> C::ICapeArrayString {
506		C::ICapeArrayString {
507			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
508			vTbl: (&Self::CAPE_ARRAY_STRING_VTABLE as *const C::ICapeArrayString_VTable).cast_mut(),
509		}
510	}
511}
512
513/// Vector based CapeArrayValueOut implementation
514///
515/// ICapeArrayValue is passed as data container between CAPE-OPEN functions. 
516/// It is up to the caller to provide the interface, and its implementation. 
517/// This class provides a default impementation using a `Vec<CapeValueImpl>`.
518///
519/// To manipulate the values, one could use the CapeArrayValueOut wrapper;
520/// only a limited number of functions are implemented here.
521///
522/// # Examples
523///
524/// ```
525/// use cobia::*;
526///
527/// fn set_content(a: &mut CapeArrayStringOut) {
528///     a.put_array(&["idealGasEnthalpy", "idealGasEntropy"]).unwrap();
529/// }
530/// 
531/// let mut arr = cobia::CapeArrayStringVec::new();
532/// set_content(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
533/// assert_eq!(arr.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
534/// ```
535pub type CapeArrayValueVec = CapeArrayObjectVec<CapeValueImpl,C::ICapeValue>;
536
537impl CapeArrayValueVec {
538
539
540	/// Initialize from CapeValueContent slice
541	///
542	/// Creates a new CapeArrayValueVec from or slice of CapeValueContent;
543	/// note that the values will be cloned.
544	///
545	/// # Arguments
546	///
547	/// * `array` - A slice of values to converted to a CapeArrayValueVec
548	///
549	/// # Examples
550	///
551	/// ```
552	/// use cobia;
553	/// let arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Real(2.4),cobia::CapeValueContent::Boolean(true)]);
554	/// assert_eq!(arr.as_value_vec(), vec![cobia::CapeValueContent::Real(2.4),cobia::CapeValueContent::Boolean(true)]);
555	/// ```
556	pub fn from_slice(array: &[CapeValueContent]) -> CapeArrayValueVec {
557		let mut vec = Vec::new();
558		let mut interface_vec = Vec::new();
559		let mut interface_ptr_vec = Vec::new();
560		vec.reserve(array.len());
561		interface_vec.reserve(array.len());
562		interface_ptr_vec.reserve(array.len());
563		for val in array.iter() {
564			vec.push(CapeValueImpl::from_content(val.clone()));
565			interface_vec.push(vec.last_mut().unwrap().as_cape_value_out());
566			interface_ptr_vec.push((interface_vec.last().unwrap() as *const C::ICapeValue).cast_mut());
567		}
568		Self {
569			vec,
570			interface_vec,
571			interface_ptr_vec
572		}
573	}
574
575	/// Return a value vector
576	///
577	/// Returns a vector of values from the CapeArrayValueVec.
578	///
579	/// # Examples
580	///
581	/// ```
582	/// use cobia;
583	/// let arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Empty,cobia::CapeValueContent::Integer(4)]);
584	/// let valvec = arr.as_value_vec();
585	/// assert_eq!(valvec, vec![cobia::CapeValueContent::Empty,cobia::CapeValueContent::Integer(4)]);
586	/// ```
587	pub fn as_value_vec(&self) -> Vec<CapeValueContent> {
588		let mut vec:Vec<CapeValueContent> = Vec::new();
589		vec.reserve(self.vec.len());
590		for val in self.vec.iter() {
591			vec.push(val.value());
592		}
593		vec
594	}
595
596	/// Resize
597	///
598	/// Change the size of the vector.
599	///
600	/// # Arguments
601	///
602	/// * `size` - The new size of the vector
603	///
604	/// # Example
605	///
606	/// ```
607	/// use cobia;
608	/// use cobia::prelude::*;
609	/// let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Empty,cobia::CapeValueContent::Integer(4)]);
610	/// arr.resize(3);
611	/// assert_eq!(arr.size(), 3);
612	/// ```
613	pub fn resize(&mut self, size: usize) {
614		let old_size = self.vec.len();
615		let size = size as usize;
616		if size < old_size {
617			self.vec.truncate(size);
618			self.interface_vec.truncate(size);
619			self.interface_ptr_vec.truncate(size);
620		} else {
621			self.vec.reserve((size - old_size) as usize);
622			self.interface_vec.reserve((size - old_size) as usize);
623			for _ in old_size..size {
624				self.vec.push(CapeValueImpl::new());
625				self.interface_vec.push(self.vec.last_mut().unwrap().as_cape_value_out());
626			}
627			//vector may have been re-allocated, redo interfaces
628			self.interface_ptr_vec.resize(size, std::ptr::null_mut());
629			for i in old_size..size {
630				self.interface_vec[i]=self.vec[i].as_cape_value_out();
631				self.interface_ptr_vec[i]=(&self.interface_vec[i] as *const C::ICapeValue).cast_mut();
632			}
633		}
634	}
635
636	/// Set the content of the value array from any object that implements CapeArrayValueProviderIn.
637	///
638	/// # Arguments
639	/// * `array` - An object that implements CapeArrayValueProviderIn
640	///
641	/// # Example
642	///
643	/// ```
644	/// use cobia;
645	/// let mut arr = cobia::CapeArrayValueVec::new();
646	/// let mut arr1 = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Empty,cobia::CapeValueContent::Integer(4)]);
647	/// arr.set(&arr1);
648	/// assert_eq!(arr.as_value_vec(), vec![cobia::CapeValueContent::Empty,cobia::CapeValueContent::Integer(4)]);
649	/// ```
650	pub fn set<T:CapeArrayValueProviderIn>(&mut self,array:&T) -> Result<(), COBIAError> {
651		let mut value_array_in_from_provider = CapeArrayValueInFromProvider::from(array);
652		let value_array=value_array_in_from_provider.as_cape_array_value_in();
653		self.resize(value_array.size());
654		for i in 0..value_array.size() {
655			self.vec[i].set(&value_array.at(i)?)?;
656		}
657		Ok(())
658	}
659
660	///interface member
661
662	extern "C" fn get(
663		me: *mut ::std::os::raw::c_void,
664		data: *mut *mut *mut C::ICapeValue,
665		size: *mut C::CapeSize,
666	) {
667		let p = me as *mut Self;
668		let str_arr: &mut Self = unsafe { &mut *p };
669		unsafe {
670			*data = str_arr.interface_ptr_vec.as_ptr() as *mut *mut C::ICapeValue;
671			*size = str_arr.interface_vec.len() as C::CapeSize;
672		}
673	}
674
675	///interface member
676
677	extern "C" fn setsize(
678		me: *mut ::std::os::raw::c_void,
679		size: C::CapeSize,
680		data: *mut *mut *mut C::ICapeValue,
681	) -> C::CapeResult {
682		let p = me as *mut Self;
683		let str_arr: &mut Self = unsafe { &mut *p };
684		str_arr.resize(size as usize);
685		unsafe {
686			*data = str_arr.interface_ptr_vec.as_ptr() as *mut *mut C::ICapeValue;
687		}
688		COBIAERR_NOERROR
689	}
690
691	///interface v-table
692
693	const CAPE_ARRAY_VALUE_VTABLE: C::ICapeArrayValue_VTable = C::ICapeArrayValue_VTable {
694		get: Some(Self::get),
695		setsize: Some(Self::setsize),
696	};
697
698
699}
700
701impl CapeArrayValueProviderIn for CapeArrayValueVec {
702	/// Convert to ICapeArrayValue
703	///
704	/// Returns a reference to the ICapeArrayValue interface.
705	///
706	/// # Examples
707	///
708	/// ```
709	/// use cobia::*;
710	/// use cobia::prelude::*;
711	/// let arr = cobia::CapeArrayValueVec::from_slice(&vec![cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
712	///	let i_cape_value=arr.as_cape_array_value_in();
713	///	let mut i_cape_value_ptr=(&i_cape_value as *const C::ICapeArrayValue).cast_mut(); //normally a pointer to the interface is received
714	///	let sa = cobia::CapeArrayValueIn::new(&mut i_cape_value_ptr); //CapeArrayValueIn from *mut C::ICapeArrayValue
715	/// assert_eq!(sa.as_value_vec().unwrap(), vec![cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
716	/// ```
717
718	fn as_cape_array_value_in(&self) -> C::ICapeArrayValue {
719		C::ICapeArrayValue {
720			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
721			vTbl: (&Self::CAPE_ARRAY_VALUE_VTABLE as *const C::ICapeArrayValue_VTable).cast_mut(),
722		}
723	}
724}
725
726impl CapeArrayValueProviderOut for CapeArrayValueVec {
727	/// Convert to ICapeArrayValue
728	///
729	/// Returns a mutable reference to the ICapeArrayValue interface.
730	///
731	/// # Examples
732	///
733	/// ```
734	/// use cobia::*;
735	/// use cobia::prelude::*;
736	/// let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
737	///	let i_cape_array_value=arr.as_cape_array_value_out();
738	///	let mut i_cape_array_value_ptr=(&i_cape_array_value as *const C::ICapeArrayValue).cast_mut(); //normally a pointer to the interface is received
739	///	let va = cobia::CapeArrayValueOut::new(&mut i_cape_array_value_ptr); //CapeArrayValueOut from *mut C::ICapeArrayValue
740	/// assert_eq!(va.as_value_vec().unwrap(), vec![cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
741	/// ```
742
743	fn as_cape_array_value_out(&mut self) -> C::ICapeArrayValue {
744		C::ICapeArrayValue {
745			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
746			vTbl: (&Self::CAPE_ARRAY_VALUE_VTABLE as *const C::ICapeArrayValue_VTable).cast_mut(),
747		}
748	}
749}
750
751impl<T: CapeArrayValueProviderIn> PartialEq<T> for CapeArrayValueVec {
752	/// Partial equality
753	///
754	/// Checks if the content of the CapeArrayValueVec is equal to the content of another object that implements CapeArrayValueProviderIn.
755	///
756	/// # Arguments
757	///
758	/// * `other` - An object that implements CapeArrayValueProviderIn
759	///
760	/// # Examples
761	///
762	/// ```
763	/// use cobia::*;
764	/// let arr1 = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
765	/// let arr2 = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
766	/// let arr3 = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Boolean(false),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
767	/// assert!(arr1 == arr2);
768	/// assert!(arr1 != arr3);
769	/// ```
770	fn eq(&self, other: &T) -> bool {
771		let mut provider=CapeArrayValueInFromProvider::from(other);
772		let other=provider.as_cape_array_value_in(); 
773		if self.size() != other.size() {
774			return false;
775		}
776		//compare the value vectors
777		for (i, v) in self.vec.iter().enumerate() {
778			match other.at(i) {
779				Ok(v_other) => {
780					if v != &v_other {
781						return false;
782					}
783				},
784				Err(_) => return false, //if we cannot get the value, they are not equal
785			}
786		}
787		true
788	}
789}