Struct RealParameter

Source
pub struct RealParameter {
    pub(crate) name: CapeStringImpl,
    description: CapeStringImpl,
    is_input: bool,
    shared_unit_data: Rc<RefCell<SharedUnitData>>,
    pub(crate) value: f64,
    default_value: f64,
    minimum_value: f64,
    maximum_value: f64,
    dimensionality: Vec<f64>,
    cobia_object_data: RealParameterCobiaObjectData,
}
Expand description

The RealParameter class implements a CAPE-OPEN 1.2 real parameter.

Parameters must implement the ICapeIdentification and ICapeParameter interfaces. In addition, real parameters must implement the ICapeRealParameter interface.

This implementation can be used for both input and output parameters. Input parameters can be set by the user, while output parameters are set by the unit operation.

The parameter is allowed to have a missing value, but for input parameters this is considered invalid.

Any other invalid values (outside the bounds of the parameter) will raise an error when set. Therefore, any parameter for which the value is not missing, is valid.

Fields§

§name: CapeStringImpl

The name of the parameter

§description: CapeStringImpl

The description of the parameter

§is_input: bool

Indicates whether this parameter is an input (true) or an output (false)

§shared_unit_data: Rc<RefCell<SharedUnitData>>

Shared data for the unit, containing unit-specific information

§value: f64

The current value of the parameter

§default_value: f64

Default value of the parameter

§minimum_value: f64

Minimum value of the parameter

§maximum_value: f64

Maximum value of the parameter

§dimensionality: Vec<f64>

Dimensionality of the parameter

§cobia_object_data: RealParameterCobiaObjectData

Cobia object data for this object, which contains generated code to provide the native COBIA interfaces

Implementations§

Source§

impl RealParameter

Source

fn create_instance( _real_parameter_boxed_ptr: *mut *mut ICapeInterface, name: CapeStringImpl, description: CapeStringImpl, is_input: bool, shared_unit_data: Rc<RefCell<SharedUnitData>>, default_value: f64, minimum_value: f64, maximum_value: f64, dimensionality: Vec<f64>, ) -> CapeResult

Source

pub(crate) fn create<T: CapeSmartPointer>( name: CapeStringImpl, description: CapeStringImpl, is_input: bool, shared_unit_data: Rc<RefCell<SharedUnitData>>, default_value: f64, minimum_value: f64, maximum_value: f64, dimensionality: Vec<f64>, ) -> T

Create a new instance of the object and return a smart pointer to it

This function panics if the created object does not implement the interface corresponding to the smart pointer to be returned. For a non-panic version, use the try_create() function.

Source

pub(crate) fn try_create<T: CapeSmartPointer>( name: CapeStringImpl, description: CapeStringImpl, is_input: bool, shared_unit_data: Rc<RefCell<SharedUnitData>>, default_value: f64, minimum_value: f64, maximum_value: f64, dimensionality: Vec<f64>, ) -> Result<T, COBIAError>

Create a new instance of the object and return a smart pointer to it

This function returns an error if the created object does not implement the interface corresponding to the smart pointer to be returned.

Source

pub(crate) unsafe fn borrow<T: CapeSmartPointer>(smart_pointer: &T) -> &Self

Get a reference to the object

Note that as the reference is created from a smart pointer, the reference is valid only as long as the smart pointer is valid. The reference is not checked for multiple borrows

§Safety

The user must ensure that the smart pointer contains a valid object, and that the object is of the type that is being borrowed. It is not possible for the compiler to check this, as the borrow is done through the native object pointer in the interface.

Source

pub(crate) unsafe fn borrow_mut<T: CapeSmartPointer>( smart_pointer: &mut T, ) -> &mut Self

Get a mutable reference to the object

Note that as the reference is created from a smart pointer, the reference is valid only as long as the smart pointer is valid. The reference is not checked for multiple borrows

§Safety

This function is unsafe because it allows mutable access to the object. Also the user must ensure that the smart pointer contains a valid object, and that the object is of the type that is being borrowed. It is not possible for the compiler to check this, as the borrow is done through the native object pointer in the interface.

Source§

impl RealParameter

Source

fn new( name: CapeStringImpl, description: CapeStringImpl, is_input: bool, shared_unit_data: Rc<RefCell<SharedUnitData>>, default_value: f64, minimum_value: f64, maximum_value: f64, dimensionality: Vec<f64>, ) -> Self

Trait Implementations§

Source§

impl Display for RealParameter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format the RealParameter as a string for display purposes.

The std::fmt::Display interface is used when generating the source name of the object that raises an error.

§Arguments:
  • f - A mutable reference to a std::fmt::Formatter where the formatted string will be written.
§Returns:
  • A std::fmt::Result indicating the success or failure of the formatting operation.
Source§

impl ICapeIdentification for RealParameter

Source§

fn get_component_name( &mut self, name: &mut CapeStringOut<'_>, ) -> Result<(), COBIAError>

Get the name of the component.

§Arguments:
  • name - A mutable reference to a CapeStringOut where the name will be set.
§Returns:
  • A Result indicating success or failure. If successful, the name is set in name.
Source§

fn get_component_description( &mut self, description: &mut CapeStringOut<'_>, ) -> Result<(), COBIAError>

Get the description of the component.

§Arguments:
  • description - A mutable reference to a CapeStringOut where the description will be set.
§Returns:
  • A Result indicating success or failure. If successful, the description is set in description.
Source§

fn set_component_name( &mut self, _name: &CapeStringIn<'_>, ) -> Result<(), COBIAError>

Set the name of the component.

This method is not allowed for this parameter implementation and will return an error.

Source§

fn set_component_description( &mut self, _desc: &CapeStringIn<'_>, ) -> Result<(), COBIAError>

Set the description of the component.

This method is not allowed for this parameter implementation and will return an error.

Source§

impl ICapeIdentificationImpl for RealParameter

Source§

type T = RealParameter

Source§

fn as_interface_pointer(&mut self) -> *mut ICapeInterface

§

fn init_interface() -> _ICapeInterface

prepare CAPEOPEN_1_2_ICapeIdentification interface and return as generic ICapeInterface pointer
§

fn init<Timpl>(u: &mut Timpl)
where Timpl: ICapeIdentificationImpl + ICapeInterfaceImpl,

§

extern "C" fn raw_get_component_name( me: *mut c_void, name: *mut _ICapeString, ) -> u32

§

extern "C" fn raw_set_component_name( me: *mut c_void, name: *mut _ICapeString, ) -> u32

§

extern "C" fn raw_get_component_description( me: *mut c_void, desc: *mut _ICapeString, ) -> u32

§

extern "C" fn raw_set_component_description( me: *mut c_void, desc: *mut _ICapeString, ) -> u32

§

const VTABLE: CAPEOPEN_1_2_ICapeIdentification_VTable = _

Source§

impl ICapeInterfaceImpl for RealParameter

Source§

type T = RealParameter

Source§

fn get_object_data(&mut self) -> &mut CapeObjectData

Returns a mutable reference to the internal CapeObjectData structure.
Source§

fn get_self(&mut self) -> *mut RealParameter

Returns a pointer to the implementing object.
§

const CAPEINTERFACE_VTABLE: ICapeInterface_VTable = _

the V-table for the ICapeInterface implementation.
§

fn init(&mut self) -> *mut _ICapeInterface

Initializes the object, setting up the interface pointer and adding it to the interface map.
§

fn create_object_data<Timpl>() -> CapeObjectData
where Timpl: ICapeInterfaceImpl,

Utility function for internal object setup
§

extern "C" fn raw_add_reference(me: *mut c_void)

§

extern "C" fn raw_release(me: *mut c_void)

§

extern "C" fn raw_query_interface( me: *mut c_void, uuid: *const _CapeUUID, interface: *mut *mut _ICapeInterface, ) -> u32

§

extern "C" fn raw_get_last_error( me: *mut c_void, error: *mut *mut _ICapeError, ) -> u32

§

fn add_interface( &mut self, uuid: *const _CapeUUID, interface: *mut _ICapeInterface, )

Utility function to add an interface to the interface map. Read more
§

fn set_last_error(&mut self, error: COBIAError, scope: &str) -> u32

Utility function to set the last error and scope. Read more
§

fn clear_last_error(&mut self)

Utility function to clear the last error and scope.
§

fn as_icapeinterface(&mut self) -> *mut _ICapeInterface

Returns a unique pointer to the ICapeInterface implementation of the object.
Source§

impl ICapeParameter for RealParameter

Source§

fn get_val_status(&mut self) -> Result<CapeValidationStatus, COBIAError>

Get the validation status of the parameter.

As this parameter does not accept any values that are not valid, the parameter is always valid if specified. However, an unspecified input value is considered invalid.

§Returns:
  • A Result containing the validation status, which is always CapeValid for this implementation.
Source§

fn get_mode(&mut self) -> Result<CapeParamMode, COBIAError>

Get the mode of the parameter.

§Returns:
  • A Result containing the mode of the parameter, which is either CapeInput or CapeOutput based on the is_input field.
Source§

fn get_type(&mut self) -> Result<CapeParamType, COBIAError>

Get the type of the parameter.

§Returns:
  • A Result containing the type of the parameter, which is always CapeParameterReal for this implementation.
Source§

fn validate( &mut self, message: &mut CapeStringOut<'_>, ) -> Result<CapeBoolean, COBIAError>

Validate the parameter.

As this parameter does not accept any values that are not valid, the parameter is always valid if specified. However, an unspecified input value is considered invalid.

§Arguments:
  • message - A mutable reference to a CapeStringOut where any validation error messages will be set.
§Returns:
  • A Result containing a CapeBoolean indicating whether the parameter is valid or not. If the input value is not specified, it returns false and sets an error message.
Source§

fn reset(&mut self) -> Result<(), COBIAError>

Reset the parameter to its default value.

This method sets the value of the parameter back to its default value and marks the unit as dirty. It also resets the validation status to CapeNotValidated.

§Returns:
  • A Result indicating success or failure. If successful, the value is reset to the default value.
Source§

impl ICapeParameterImpl for RealParameter

Source§

type T = RealParameter

Source§

fn as_interface_pointer(&mut self) -> *mut ICapeInterface

§

fn init_interface() -> _ICapeInterface

prepare CAPEOPEN_1_2_ICapeParameter interface and return as generic ICapeInterface pointer
§

fn init<Timpl>(u: &mut Timpl)
where Timpl: ICapeParameterImpl + ICapeInterfaceImpl,

§

extern "C" fn raw_get_val_status( me: *mut c_void, val_status: *mut i32, ) -> u32

§

extern "C" fn raw_get_mode(me: *mut c_void, mode: *mut i32) -> u32

§

extern "C" fn raw_get_type( me: *mut c_void, parameter_type: *mut i32, ) -> u32

§

extern "C" fn raw_validate( me: *mut c_void, message: *mut _ICapeString, is_ok: *mut u32, ) -> u32

§

extern "C" fn raw_reset(me: *mut c_void) -> u32

§

const VTABLE: CAPEOPEN_1_2_ICapeParameter_VTable = _

Source§

impl ICapeRealParameter for RealParameter

Source§

fn get_value(&mut self) -> Result<CapeReal, COBIAError>

Get the value of the parameter.

This method retrieves the current value of the parameter.

§Returns:
  • A Result containing the current value of the parameter as CapeReal.
Source§

fn set_value(&mut self, value: CapeReal) -> Result<(), COBIAError>

Set the value of the parameter.

This implementation accepts a blank value for the parameters, but it does not allow an invalid value to be set.

Only input parameters can be set.

If the value is set, it marks the unit as dirty and not validated.

§Arguments:
  • value - The value to set for the parameter, which should be a CapeReal.
§Returns:
  • A Result indicating success or failure.
Source§

fn get_default_value(&mut self) -> Result<CapeReal, COBIAError>

Get the default value of the parameter.

This method retrieves the default value of the parameter.

If the default value is not available (NaN), it returns an error.

§Returns:
  • A Result containing the default value of the parameter as CapeReal, or an error.
Source§

fn get_lower_bound(&mut self) -> Result<CapeReal, COBIAError>

Get the lower bound of the parameter.

This method retrieves the lower bound of the parameter.

If the lower bound is not available (NaN), it returns an error.

§Returns:
  • A Result containing the lower bound of the parameter as CapeReal, or an error.
Source§

fn get_upper_bound(&mut self) -> Result<CapeReal, COBIAError>

Get the upper bound of the parameter.

This method retrieves the upper bound of the parameter.

If the upper bound is not available (NaN), it returns an error.

§Returns:
  • A Result containing the upper bound of the parameter as CapeReal, or an error.
Source§

fn get_dimensionality( &mut self, dimensionality: &mut CapeArrayRealOut<'_>, ) -> Result<(), COBIAError>

Get the dimensionality of the parameter.

This method retrieves the dimensionality of the parameter, as a vector of coefficients to the SI units m, kg, S, A, K, mole, cd, rad.

An additional relative flag is present at the end of the vector to indicate whether the parameter is relative to a reference value (non-zero) or absolute (zero); for example a pressure difference or temperature difference is relative, and unit conversions should ignore the offset in the unit conversion.

A special case for the use of the relative flag is a dimensionless parameter with the relative flag set to true, which indicates that the parameter is a fraction or percentage, and should be treated as such in unit conversions.

Any zero valued trailing coefficients may be omitted, so that the dimensionality vector may have a size of between 0 and 9 elements.

This implementation returns the dimensionality of the parameter as passed to the construction of the parameter.

§Arguments:
  • dimensionality - A mutable reference to a CapeArrayRealOut where the dimensionality will be set.
§Returns:
  • A Result indicating success or failure. If successful, the dimensionality is set in dimensionality.
Source§

fn validate( &mut self, value: CapeReal, message: &mut CapeStringOut<'_>, ) -> Result<CapeBoolean, COBIAError>

Validate whether a given value is valid for this parameter.

This method checks if the provided value is within the bounds of the parameter and meets the dimensionality requirements.

Note that a missing value (NaN) is considered invalid, but may be set nevertheless, which puts the parameter in an invalid state.

Output parameters are not validated, as they are set by the unit operation and not by the user.

§Arguments:
  • value - The value to validate, which should be a CapeReal.
  • message - A mutable reference to a CapeStringOut where any validation error messages will be set.
§Returns:
  • A Result containing a CapeBoolean indicating whether the value is valid or not. If the value is not valid, it sets an error message in message.
Source§

impl ICapeRealParameterImpl for RealParameter

Source§

type T = RealParameter

Source§

fn as_interface_pointer(&mut self) -> *mut ICapeInterface

§

fn init_interface() -> _ICapeInterface

prepare CAPEOPEN_1_2_ICapeRealParameter interface and return as generic ICapeInterface pointer
§

fn init<Timpl>(u: &mut Timpl)
where Timpl: ICapeRealParameterImpl + ICapeInterfaceImpl,

§

extern "C" fn raw_get_value(me: *mut c_void, value: *mut f64) -> u32

§

extern "C" fn raw_set_value(me: *mut c_void, value: f64) -> u32

§

extern "C" fn raw_get_default_value( me: *mut c_void, default_value: *mut f64, ) -> u32

§

extern "C" fn raw_get_lower_bound( me: *mut c_void, l_bound: *mut f64, ) -> u32

§

extern "C" fn raw_get_upper_bound( me: *mut c_void, u_bound: *mut f64, ) -> u32

§

extern "C" fn raw_get_dimensionality( me: *mut c_void, dimensionality: *mut ICapeArrayReal, ) -> u32

§

extern "C" fn raw_validate( me: *mut c_void, value: f64, message: *mut _ICapeString, is_ok: *mut u32, ) -> u32

§

const VTABLE: CAPEOPEN_1_2_ICapeRealParameter_VTable = _

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> 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.