op_vvec_value_get()
Abstract
Copies a value within a value vector to a specified variable.
Syntax
op_vvec_value_get (source, position, value_ptr)
| Argument | Type | Description |
|---|---|---|
source |
Vvec_Vector |
value vector from which to retrieve the value |
position |
unsigned int |
index number of the value to be retrieved |
value_ptr |
void * |
pointer to the variable that will hold the value retrieved |
Return Type
Compcode
Completion code indicating success or failure in getting the value.
This procedure returns OPC_COMPCODE_SUCCESS if the value was successfully retrieved. It returns OPC_COMPCODE_FAILURE if it could not retrieve the value. Failure might occur, for example, if position is past the end of the vector.
Example
/* Run through an integer vector and calculate a sum of all of its components. */
sum = 0;
for (i = 0; i < op_vvec_size_get (target_vector); i++)
{
/* get current value. */
op_vvec_value_get (target_vector, i, &val);
sum = sum + val;
}
/* sum now contains the summation over the value vector. */
Details
For value vectors of type OpC_Type_Boolean or OpC_Type_Bit, this function returns one of the following constants:
- OpC_Bool_F and OpC_Bool_T for boolean
- OpC_Bit_0 and OpC_Bit_1 for bit
Purpose
Provide a mechanism to read single elements from value vectors.
Errors
- Recoverable Error: Value vector is invalid.
- Recoverable Error: Position (
<pos>) exceeds element count of value vector. - Recoverable Error: Destination value pointer is invalid.
Reference
- Use the KP op_vvec_value_set() to set a value in 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