op_vvec_value_set()
Abstract
Assign a value to a specific element in a value vector.
Syntax
op_vvec_value_set (target, position, value)
| Argument | Type | Description |
|---|---|---|
target |
Vvec_Vector |
value vector to be modified |
position |
unsigned int |
index number of the value to be set |
value |
Vartype |
value to place into the vector at position |
Return Type
Compcode
Completion code indicating success or failure in setting the value.
The procedure returns OPC_COMPCODE_SUCCESS if the value was successfully set. It returns OPC_COMPCODE_FAILURE if it could not set the value. Failure might occur, for example, if there is insufficient memory to expand the vector.
Example
/* Run through a STDLOGIC value vector and change all occurrences of 'Z' to '0'. */
for (i = 0; i < op_vvec_size (target_vector); i++)
{
/* get current value. */
op_vvec_value_get (target_vector, i, &val);
/* test for equality. */
if (val == 'Z')
{
op_vvec_value_set (target_vector, i, '0');
}
}
Details
For value vectors of type OpC_Type_Boolean or OpC_Type_Bit, do not assign the literal values 0 and 1. Instead, use the corresponding constants:
- OpC_Bool_F and OpC_Bool_T for boolean
- OpC_Bit_0 and OpC_Bit_1 for bit
If the vector element specified by position is past the end of the vector, op_vvec_value_set() expands the vector, creating the new position and all elements needed to increase the vector to the new size. Unspecified values are set to the following defaults:
Table 23: op_vvec_value_set() Default Values by Type
| Value Type | Default |
|---|---|
| integer | 0 |
| double | 0.0 |
| pointer | OPC_NULL (for pointers) |
| char | \0' (for char) |
| bit | OPC_BIT_0 |
| standard logic | “0” |
| boolean | OPC_BOOL_F |
Purpose
Provide a mechanism to assign values to individual elements within existing value vectors.
Errors
- Recoverable Error: Value vector is invalid.
- Recoverable Error: Insufficient memory to set value at position (
<pos>).
Reference
- Use the KP op_vvec_value_get() to retrieve a value from a value vector
- Use the KP op_vvec_create() to create a new value vector
- Use the KP op_vvec_copy() to create a new value vector that contains a copy of another
- Use the KP op_vvec_destroy() to deallocate memory associated with a value vector