op_vvec_value_get()
摘要
将值向量中的一个值复制到指定变量。
语法
op_vvec_value_get (source, position, value_ptr)
| 参数 | 类型 | 说明 |
|---|---|---|
source |
Vvec_Vector |
要从中取值的值向量 |
position |
unsigned int |
要取值的索引号 |
value_ptr |
void * |
用于存放所取值的变量的指针 |
返回类型
Compcode
完成代码,指示取值操作的成功或失败。
若取值成功,该过程返回 OPC_COMPCODE_SUCCESS;若无法取值,则返回 OPC_COMPCODE_FAILURE。例如,当 position 超出向量末尾时可能发生失败。
示例
/* 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. */
详情
对于类型为 OpC_Type_Boolean 或 OpC_Type_Bit 的值向量,该函数返回下列常量之一:
- 布尔类型使用 OpC_Bool_F 和 OpC_Bool_T
- 比特类型使用 OpC_Bit_0 和 OpC_Bit_1
用途
提供一种从值向量中读取单个元素的方法。
错误
- 可恢复错误:值向量无效。
- 可恢复错误:位置(
<pos>)超出值向量的元素数量。 - 可恢复错误:目标值指针无效。
参考
- 使用内核过程 op_vvec_value_set() 在值向量中设置一个值
- 使用内核过程 op_vvec_create() 创建一个新值向量
- 使用内核过程 op_vvec_copy() 创建一个包含另一个值向量副本的新值向量
- 使用内核过程 op_vvec_destroy() 释放与值向量关联的内存