pub struct CapeArrayValueOut<'a> {
interface: &'a mut *mut ICapeArrayValue,
data: *mut *mut ICapeValue,
size: CapeSize,
}Expand description
CapeArrayValueOut wraps an ICapeArrayValue interface pointer.
Given a reference to an ICapeArrayValue interface pointer, this allows setting and getting the elements.
This interface is typically used as arguments to rust methods on traits that are generated from CAPE-OPEN interfaces that have ICapeArrayValue output arguments.
NULL interface pointers are not allowed.
§Examples
use cobia::*;
fn set_content(a: &mut CapeArrayValueOut) {
a.put_array(&[cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]).unwrap();
}
let mut arr = cobia::CapeArrayValueVec::new();
set_content(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());
assert_eq!(arr.as_value_vec(), vec![cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);Fields§
§interface: &'a mut *mut ICapeArrayValue§data: *mut *mut ICapeValue§size: CapeSizeImplementations§
Source§impl<'a> CapeArrayValueOut<'a>
impl<'a> CapeArrayValueOut<'a>
Sourcepub fn new(interface: &'a mut *mut ICapeArrayValue) -> CapeArrayValueOut<'a>
pub fn new(interface: &'a mut *mut ICapeArrayValue) -> CapeArrayValueOut<'a>
Create a new CapeValueOut from an ICapeArrayValue interface pointer.
§Arguments
interface- A pointer to an ICapeArrayValue interface
§Examples
use cobia::*;
use cobia::prelude::*;
let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
let i_cape_array_value=arr.as_cape_array_value_out();
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
let va = cobia::CapeArrayValueOut::new(&mut i_cape_array_value_ptr); //CapeArrayValueOut from *mut C::ICapeArrayValue
assert_eq!(va.as_value_vec().unwrap(), vec![cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Return the size of the array
§Examples
use cobia::*;
fn check_size(a: &mut CapeArrayValueOut) {
assert_eq!(a.size(), 3);
}
let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Boolean(true),cobia::CapeValueContent::Real(1.2),cobia::CapeValueContent::Empty]);
check_size(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the array is empty
§Examples
use cobia::*;
fn check_empty(a: &mut CapeArrayValueOut) {
assert!(a.is_empty());
}
let mut arr = cobia::CapeArrayValueVec::new();
check_empty(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());Sourcepub fn put_array(
&mut self,
array: &[CapeValueContent],
) -> Result<(), COBIAError>
pub fn put_array( &mut self, array: &[CapeValueContent], ) -> Result<(), COBIAError>
Set the content from a slice of CapeValueContent
§Arguments
arr- A slice of CapeValueContent
§Examples
use cobia::*;
fn set_content(a: &mut CapeArrayValueOut) {
a.put_array(&[cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::Empty,cobia::CapeValueContent::Boolean(true)]).unwrap();
}
let mut arr = cobia::CapeArrayValueVec::new();
set_content(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());
assert_eq!(arr.as_value_vec(), [cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::Empty,cobia::CapeValueContent::Boolean(true)]); //the values have been stored on the object that implements ICapeArrayValueSourcepub fn at(&self, index: usize) -> Result<CapeValueOut<'a>, COBIAError>
pub fn at(&self, index: usize) -> Result<CapeValueOut<'a>, COBIAError>
Get an element
§Arguments
index- The index of the element to get
Note that neither Index and IndexMut is provided for CapeArrayValueOut, because these interfaces yield a reference to the element, whereas the elements of CapeArrayValueOut are represented by an interface, which is conveniently wrapped into CapeValueOut.
Note that the life time of the CapeValueOut is tied to the life time of the CapeArrayValueOut.
§Examples
use cobia::*;
fn test_element(a: &mut CapeArrayValueOut) {
assert_eq!(a.at(2).unwrap().get_boolean().unwrap(), true);
}
let mut arr = cobia::CapeArrayValueVec::from_slice(&vec![cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::Empty,cobia::CapeValueContent::Boolean(true)]);
test_element(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());
assert_eq!(arr.as_value_vec(), [cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::Empty,cobia::CapeValueContent::Boolean(true)]); //the values have been stored on the object that implements ICapeArrayValueSourcepub fn as_value_vec(&self) -> Result<Vec<CapeValueContent>, COBIAError>
pub fn as_value_vec(&self) -> Result<Vec<CapeValueContent>, COBIAError>
Return the content of the value array as a vector of CapeValueContent
§Examples
use cobia::*;
fn test_content(a: &mut CapeArrayValueOut) {
assert_eq!(a.as_value_vec().unwrap(), vec![cobia::CapeValueContent::Real(2.4),cobia::CapeValueContent::Boolean(true)]);
}
let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Real(2.4),cobia::CapeValueContent::Boolean(true)]);
test_content(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());Sourcepub fn resize(&mut self, size: usize) -> Result<(), COBIAError>
pub fn resize(&mut self, size: usize) -> Result<(), COBIAError>
Resize
§Arguments
size- The new size of the array
§Examples
use cobia::*;
fn set_content(a: &mut CapeArrayValueOut) {
a.resize(3).unwrap();
a.at(0).unwrap().set_string("idealGasEnthalpy").unwrap();
a.at(1).unwrap().set_real(2.4).unwrap();
a.at(2).unwrap().set_integer(0).unwrap();
}
let mut arr = cobia::CapeArrayValueVec::new();
set_content(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());
assert_eq!(arr.as_value_vec(), vec![cobia::CapeValueContent::String("idealGasEnthalpy".to_string()),cobia::CapeValueContent::Real(2.4),cobia::CapeValueContent::Integer(0)]); //the values have been stored on the object that implements ICapeArrayStringSourcepub fn put_value(
&mut self,
index: usize,
value: CapeValueContent,
) -> Result<(), COBIAError>
pub fn put_value( &mut self, index: usize, value: CapeValueContent, ) -> Result<(), COBIAError>
Set an element
§Arguments
index- The index of the element to setvalue- The value to set
§Examples
use cobia::*;
fn set_element(a: &mut CapeArrayValueOut) {
a.put_value(1, cobia::CapeValueContent::String("density".to_string())).unwrap();
}
let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::Empty,cobia::CapeValueContent::Boolean(true)]);
set_element(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());
assert_eq!(arr.as_value_vec(), [cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::String("density".to_string()),cobia::CapeValueContent::Boolean(true)]);Sourcepub fn set<T: CapeArrayValueProviderIn>(
&mut self,
array: &T,
) -> Result<(), COBIAError>
pub fn set<T: CapeArrayValueProviderIn>( &mut self, array: &T, ) -> Result<(), COBIAError>
Set the content of the value array from any object that implements CapeArrayValueProviderIn.
§Arguments
array- An object that implements CapeArrayValueProviderIn
§Examples
use cobia::*;
let mut arr = cobia::CapeArrayValueVec::new();
let mut arr1 = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::Real(2.4),cobia::CapeValueContent::Boolean(true)]);
CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out().set(&arr1);
assert_eq!(arr.as_value_vec(), vec![cobia::CapeValueContent::Real(2.4),cobia::CapeValueContent::Boolean(true)]);Source§impl<'a> CapeArrayValueOut<'a>
impl<'a> CapeArrayValueOut<'a>
Sourcepub fn iter(&self) -> CapeArrayValueIterator<'_> ⓘ
pub fn iter(&self) -> CapeArrayValueIterator<'_> ⓘ
Return an iterator over the value array.
§Examples
use cobia::*;
fn check_iter(a: &mut CapeArrayValueOut) {
let mut iter = a.iter();
assert_eq!(iter.next().unwrap().get_string().unwrap(), "methane".to_string());
assert_eq!(iter.next().unwrap().get_type().unwrap(), cobia::CapeValueType::Empty);
assert_eq!(iter.next().unwrap().get_boolean().unwrap(), true);
assert!(!iter.next().is_some());
}
let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::Empty,cobia::CapeValueContent::Boolean(true)]);
check_iter(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());Trait Implementations§
Source§impl<'a> CapeArrayValueProviderOut for CapeArrayValueOut<'a>
impl<'a> CapeArrayValueProviderOut for CapeArrayValueOut<'a>
Source§fn as_cape_array_value_out(&mut self) -> ICapeArrayValue
fn as_cape_array_value_out(&mut self) -> ICapeArrayValue
Source§impl<'a> Display for CapeArrayValueOut<'a>
impl<'a> Display for CapeArrayValueOut<'a>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Display the content of the value array as a value vector.
§Examples
use cobia::*;
fn check_format(a: &mut CapeArrayValueOut) {
assert_eq!(format!("{}", a), "[\"methane\", <empty>, true]");
}
let mut arr = cobia::CapeArrayValueVec::from_slice(&[cobia::CapeValueContent::String("methane".to_string()),cobia::CapeValueContent::Empty,cobia::CapeValueContent::Boolean(true)]);
check_format(&mut CapeArrayValueOutFromProvider::from(&mut arr).as_cape_array_value_out());