Attribute Macro cape_object_implementation

Source
#[cape_object_implementation]
Expand description

The cape_object_implementation macro generates the necessary code to implement a COBIA object.

It provides the ICapeInterface implementation, implements error handling, reference counting and QueryInterface.

This macro is used for a class implementation that is a COBIA object. The class must implement the ICapeObject interface, and the macro will generate the necessary code to implement the COBIA object.

Arguments to this macro may include the following:

  • interfaces - a set of CAPE-OPEN interfaces to be implemented. For each interface the raw functions are automatically implemented, and the class is expected to implement the corresponding Impl trait. E.g. when specifying cape_open_1_2::ICapeIdentification one must provide trait implementation cape_open_1_2::ICapeIdentificationImpl.
  • create_arguments - if specified, a set of arguments used to intialize the fields of the struct. The arguments must match the name of the fields in the struct, and will have the same type in the struct. Any arguments present in the struct but not in the arguments will be initialized through std::default::Default::default().
  • new_arguments - if specified, a set of arguments used to pass to a function new that is implemented by the impl block of the struct, with the same arguments. These arguments must then be passed to the create or try_create.

Arguments are separated from their names by an equal sign, e.g.

interfaces={
		cape_open_1_2::ICapeIdentification,
		cape_open_1_2::ICapeCollection<cape_open_1_2::CapeUnitPort>,
	}

In addition to using this macro, a COBIA object class must also initialize its generated memeber cobia_object_data in its constructor. This member can be set to Default::default()

The following traits must be implemented for the object:

  • std::fmt::Display, which is used to get a description of the object for error handing; it is advised to include the object’s type and name
  • if the object is a primary PMC object that must be registered, also cobia::PMCRegisterationInfo
  • any other interfaces that the object implements, specified through the attribute

§Example:

See the distillation_shortcut_unit.rs file in the examples/distillation_shortcut_unit crate for an example of how to use this macro. See the salt_water_property_package.rs file in the examples/salt_water crate for an example of how to use this macro.