op_ima_sim_attr_exists()
Abstract
Determines whether a simulation attribute value is defined in the environment of a simulation.
Syntax
op_ima_sim_attr_exists (attr_name)
| Argument | Type | Description |
|---|---|---|
attr_name |
const char* |
name of the attribute-of-interest |
Return Type
Boolean
Boolean indicating whether the specified attribute value is defined in the environment.
This value will be equal to the constant OPC_TRUE if the attribute value is defined; otherwise the return value will be OPC_FALSE.
Example
/** This procedure loads in the .gdf file that specifies the link **/
/** configuration via the 'user id' attribute of duplex links. **/
/** If there is any error, an error message will be displayed and **/
/** the simulation terminated. **/
FIN (ams_atm_sw_link_table_setup ());
/* If the table has already been loaded in, just return the pointer. */
if (vp_lt_ptr != OPC_NIL)
FRET (vp_lt_ptr);
/* Check if the simulation attribute exists */
if (op_ima_sim_attr_exists ("vp_config_file") == OPC_FALSE)
FRET (OPC_NIL)
/* First, obtain name of configuration file. */
op_ima_sim_attr_get (OPC_IMA_STRING, "vp_config_file", vp_config_file);
Details
Values for simulation attributes are assigned via an environment attribute mechanism: either the simulation’s command line, the preferences file, a shell variable, or an environment file. The KP op_ima_sim_attr_get() causes the simulation’s internal database to be scanned for possible values. If it cannot find the value in the internal database, it will request a value from the user via the standard output device. Once a value is obtained from an environment attribute mechanism or from the user, it is added to the simulation’s internal database.
If the simulation attribute has a value specified in the simulation’s internal database, this KP will return OPC_TRUE; otherwise, OPC_FALSE. Therefore, if a call to op_ima_sim_attr_exists() returns OPC_FALSE for an attribute, then a call to op_ima_sim_attr_get() will query the query the standard output device for a value.
Purpose
Simulation attributes can be obtained dynamically using the KP op_ima_sim_attr_get(). However, if no value has been specified for a specified simulation attribute, the KP will request a value from the user via the standard output device. Using the KP op_ima_sim_attr_exists(), a process or pipeline stage can prevent the simulation from querying the user directly for an attribute value.
In some cases, simulation attributes are defined on a conditional basis. Also attribute names may be dependent on information which is determined dynamically. In such cases, a process or pipeline stage may need to test for the presence of a simulation attribute via op_ima_sim_attr_exists() prior to obtaining its value.
Errors
- Program Abort: Segmentation violation (due to an invalid address for attr_name)
Reference
- Use the KPs op_ima_sim_attr_get(), op_ima_sim_attr_get_dbl(), op_ima_sim_attr_get_int32(), and op_ima_sim_attr_get_str() to obtain a simulation attribute’s value