Struct CapeArrayValueOut

Source
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: CapeSize

Implementations§

Source§

impl<'a> CapeArrayValueOut<'a>

Source

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]);
Source

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());
Source

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());
Source

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 ICapeArrayValue
Source

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 ICapeArrayValue
Source

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());
Source

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 ICapeArrayString
Source

pub fn put_value( &mut self, index: usize, value: CapeValueContent, ) -> Result<(), COBIAError>

Set an element

§Arguments
  • index - The index of the element to set
  • value - 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)]);
Source

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>

Source

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>

Source§

fn as_cape_array_value_out(&mut self) -> ICapeArrayValue

Convert to ICapeArrayValue
Source§

impl<'a> Display for CapeArrayValueOut<'a>

Source§

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());

Auto Trait Implementations§

§

impl<'a> Freeze for CapeArrayValueOut<'a>

§

impl<'a> RefUnwindSafe for CapeArrayValueOut<'a>

§

impl<'a> !Send for CapeArrayValueOut<'a>

§

impl<'a> !Sync for CapeArrayValueOut<'a>

§

impl<'a> Unpin for CapeArrayValueOut<'a>

§

impl<'a> !UnwindSafe for CapeArrayValueOut<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.