Struct CapeValueImpl

Source
pub struct CapeValueImpl {
    value: CapeValueContent,
    str_val: CapeStringImpl,
}
Expand description

Default CapeValue implementation

ICapeValue is passed as data container between CAPE-OPEN functions. It is up to the caller to provide the interface, and its implementation. This class provides a default impementation.

This class can be used as input and output argument.

§Examples

use cobia::*;

fn set_value(v: &mut CapeValueOut) {
    v.set_string("my value").unwrap();
}
 
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), CapeValueContent::String("my value".into()));

Fields§

§value: CapeValueContent§str_val: CapeStringImpl

Implementations§

Source§

impl CapeValueImpl

Source

const VTABLE: ICapeValue_VTable

Interface v-table

Source

pub fn new() -> Self

Create a new, empty, CapeValueImpl

Creates a new empty CapeValueImpl

§Examples
use cobia::*;

fn set_value(v: &mut CapeValueOut) {
    v.set_string("my value").unwrap();
}
 
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), CapeValueContent::String("my value".into()));
Source

pub fn from_str(value: &str) -> Self

Create a new CapeValueImpl from string

Creates a new CapeValueImpl from the given string

§Arguments
  • value - The initial value
§Examples
use cobia::*;

fn check_value(v: &CapeValueIn) {
    assert_eq!(v.get_string().unwrap(), "C2H6".to_string());
}
 
let val = cobia::CapeValueImpl::from_str("C2H6");
check_value(&CapeValueInFromProvider::from(&val).as_cape_value_in());
Source

pub fn from_string(value: String) -> Self

Create a new CapeValueImpl from string

Creates a new CapeValueImpl from the given string

§Arguments
  • value - The initial value
§Examples
use cobia::*;

fn check_value(v: &CapeValueIn) {
    assert_eq!(v.get_string().unwrap(), "C2H6".to_string());
}
 
let val = cobia::CapeValueImpl::from_string("C2H6".to_string());
check_value(&CapeValueInFromProvider::from(&val).as_cape_value_in());
Source

pub fn from_content(value: CapeValueContent) -> Self

Create a new CapeValueImpl from content

Creates a new CapeValueImpl from the given CapeValueContent

§Arguments
  • value - The initial value
§Examples
use cobia::*;

fn check_value(v: &CapeValueIn) {
    assert_eq!(v.get_string().unwrap(), "n-butane".to_string());
}
 
let val = cobia::CapeValueImpl::from_content(cobia::CapeValueContent::String("n-butane".into()));
check_value(&CapeValueInFromProvider::from(&val).as_cape_value_in());
Source

pub fn from_integer(value: CapeInteger) -> Self

Create a new CapeValueImpl from integer

Creates a new CapeValueImpl from the given integer

§Arguments
  • value - The initial value
§Examples
use cobia::*;

fn check_value(v: &CapeValueIn) {
    assert_eq!(v.get_integer().unwrap(),5);
}
 
let val = cobia::CapeValueImpl::from_integer(5);
check_value(&CapeValueInFromProvider::from(&val).as_cape_value_in());
Source

pub fn from_boolean(value: bool) -> Self

Create a new CapeValueImpl from boolean

Creates a new CapeValueImpl from the given boolean

§Arguments
  • value - The initial value
§Examples
use cobia::*;

fn check_value(v: &CapeValueIn) {
    assert_eq!(v.get_boolean().unwrap(),false);
}
 
let val = cobia::CapeValueImpl::from_boolean(false);
check_value(&CapeValueInFromProvider::from(&val).as_cape_value_in());
Source

pub fn from_real(value: CapeReal) -> Self

Create a new CapeValueImpl from real

Creates a new CapeValueImpl from the given real

§Arguments
  • value - The initial value
§Examples
use cobia::*;

fn check_value(v: &CapeValueIn) {
    assert_eq!(v.get_real().unwrap(),3.0);
}
 
let val = cobia::CapeValueImpl::from_real(3.0);
check_value(&CapeValueInFromProvider::from(&val).as_cape_value_in());
Source

pub fn reset(&mut self)

Set to empty

Change the type to empty

§Examples
use cobia::*;
let mut val = cobia::CapeValueImpl::from_real(3.0);
val.reset();
assert_eq!(val.value(), CapeValueContent::Empty);
Source

pub fn set_string(&mut self, value: String)

Set to string

Change the type to the given string

§Arguments
  • value - The new value
§Examples
use cobia::*;
let mut val = cobia::CapeValueImpl::new();
val.set_string("H2O".into());
assert_eq!(val.value(), CapeValueContent::String("H2O".into()));
Source

pub fn set_str<T: AsRef<str>>(&mut self, value: T)

Set to string

Change the type to the given string

§Arguments
  • value - The new value
§Examples
use cobia::*;
let mut val = cobia::CapeValueImpl::new();
val.set_str("H2O");
assert_eq!(val.value(), CapeValueContent::String("H2O".into()));
Source

pub fn set_integer(&mut self, value: CapeInteger)

Set to integer

Change the type to the given integer

§Arguments
  • value - The new value
§Examples
use cobia::*;
let mut val = cobia::CapeValueImpl::new();
val.set_integer(5);
assert_eq!(val.value(), CapeValueContent::Integer(5));
Source

pub fn set_boolean(&mut self, value: bool)

Set to boolean

Change the type to the given boolean

§Arguments
  • value - The new value
§Examples
use cobia::*;
let mut val = cobia::CapeValueImpl::new();
val.set_boolean(true);
assert_eq!(val.value(), CapeValueContent::Boolean(true));
val.set_boolean(false);
assert_eq!(val.value(), CapeValueContent::Boolean(false));
Source

pub fn set_real(&mut self, value: CapeReal)

Set to real

Change the type to the given real

§Arguments
  • value - The initial value
§Examples
use cobia::*;
let mut val = cobia::CapeValueImpl::new();
val.set_real(3.1);
assert_eq!(val.value(), CapeValueContent::Real(3.1));
Source

pub fn set<T: CapeValueProviderIn>(&mut self, val: &T) -> Result<(), COBIAError>

Set the content of the value from any object that implements CapeValueProviderIn.

§Arguments
  • val - An object that implements CapeValueProviderIn
§Example
use cobia;
let mut val = cobia::CapeValueImpl::new();
let val1 = cobia::CapeValueImpl::from_str("test");
val.set(&val1);
assert_eq!(val.value(), cobia::CapeValueContent::String("test".into()));

fn set_value(val: &mut cobia::CapeValueImpl,v: &cobia::CapeValueIn) {
    val.set(v);
}
 
let val2 = cobia::CapeValueImpl::from_str("test2");
set_value(&mut val,&cobia::CapeValueInFromProvider::from(&val2).as_cape_value_in());
assert_eq!(val.value(), cobia::CapeValueContent::String("test2".into()));
Source

pub fn value_ref(&self) -> &CapeValueContent

Get a reference to the value

Returns a reference to the value

§Examples
use cobia;
let val = cobia::CapeValueImpl::from_str("test");
assert_eq!(val.value_ref(),&cobia::CapeValueContent::String("test".into()));
Source

pub fn value_ref_mut(&mut self) -> &mut CapeValueContent

Get a mutable reference to the value

Returns a mutable reference to the value

§Examples
use cobia;
use cobia::prelude::*;
let mut val = cobia::CapeValueImpl::from_integer(2);
*val.value_ref_mut()=cobia::CapeValueContent::Boolean(false);
assert_eq!(val.value_ref(),&cobia::CapeValueContent::Boolean(false));
Source

pub fn value(&self) -> CapeValueContent

Get a clone of the value

Returns a clone of the value

§Examples
use cobia;
use cobia::prelude::*;
let val = cobia::CapeValueImpl::from_integer(2);
assert_eq!(val.value(),cobia::CapeValueContent::Integer(2));
Source

extern "C" fn get_value_type(me: *mut c_void) -> CapeValueType

Interface member function

Source

extern "C" fn get_string_value( me: *mut c_void, data: *mut *const CapeCharacter, size: *mut CapeSize, ) -> CapeResult

Interface member function

Source

extern "C" fn get_integer_value( me: *mut c_void, value: *mut CapeInteger, ) -> CapeResult

Interface member function

Source

extern "C" fn get_boolean_value( me: *mut c_void, value: *mut CapeBoolean, ) -> CapeResult

Interface member function

Source

extern "C" fn get_real_value( me: *mut c_void, value: *mut CapeReal, ) -> CapeResult

Interface member function

Source

extern "C" fn set_string_value( me: *mut c_void, data: *const CapeCharacter, size: CapeSize, ) -> CapeResult

Interface member function

Source

extern "C" fn set_integer_value( me: *mut c_void, value: CapeInteger, ) -> CapeResult

Interface member function

Source

extern "C" fn set_boolean_value( me: *mut c_void, value: CapeBoolean, ) -> CapeResult

Interface member function

Source

extern "C" fn set_real_value( me: *mut c_void, value: CapeReal, ) -> CapeResult

Interface member function

Source

extern "C" fn clear(me: *mut c_void) -> CapeResult

Interface member function

Trait Implementations§

Source§

impl CapeValueProviderIn for CapeValueImpl

Source§

fn as_cape_value_in(&self) -> ICapeValue

Convert to ICapeValue

Returns a reference to the ICapeValue interface.

§Examples
use cobia::*;
use cobia::prelude::*;
let val = cobia::CapeValueImpl::from_integer(2);
let i_cape_value=val.as_cape_value_in();
let mut i_cape_value_ptr=(&i_cape_value as *const C::ICapeValue).cast_mut(); //normally a pointer to the interface is received
let v = cobia::CapeValueIn::new(&mut i_cape_value_ptr); //CapeValueIn from *mut C::ICapeValue
assert_eq!(v.get_integer().unwrap(), 2);
Source§

impl CapeValueProviderOut for CapeValueImpl

Source§

fn as_cape_value_out(&mut self) -> ICapeValue

Convert to ICapeValue

Returns a mutable reference to the ICapeValue interface.

§Examples
use cobia::*;
use cobia::prelude::*;
let mut val = cobia::CapeValueImpl::new();
let i_cape_value=val.as_cape_value_out();
let mut i_cape_value_ptr=(&i_cape_value as *const C::ICapeValue).cast_mut(); //normally a pointer to the interface is received
let mut v = cobia::CapeValueOut::new(&mut i_cape_value_ptr); //CapeValueOut from *mut C::ICapeValue
v.set_real(2.5).unwrap();
assert_eq!(val.value(), cobia::cape_value_impl::CapeValueContent::Real(2.5));
Source§

impl Clone for CapeValueImpl

Source§

fn clone(&self) -> CapeValueImpl

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for CapeValueImpl

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: CapeValueProviderIn> PartialEq<T> for CapeValueImpl

Source§

fn eq(&self, other: &T) -> bool

Partial equality

Checks if the content of the CapeValueVec is equal to the content of another object that implements CapeValueProviderIn.

§Arguments
  • other - An object that implements CapeValueProviderIn
§Examples
use cobia::*;
let val1 = cobia::CapeValueImpl::from_integer(2);
let val2 = cobia::CapeValueImpl::from_integer(2);
let val3 = cobia::CapeValueImpl::from_boolean(true);
assert!(val1 == val2);
assert!(val1 != val3);
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.