op_vvec_copy()
Abstract
Returns a new value vector that contains the same elements as the original value vector, starting at the position specified in the original vector and containing count elements.
Syntax
op_vvec_copy (original, position, count)
| Argument | Type | Description |
|---|---|---|
original |
Vvec_Vector |
value vector to be copied |
position |
unsigned int |
starting position of first value to be copied [The first position in a value vector has an index of 0. You can also use any of the value vector position constants to indicate the starting position for this procedure (see Table 99 “Value Vector Position Symbolic Constants“ on page 35).] |
count |
unsigned int |
number of values to be copied [Use a position of 0 and a count of OPC_VVEC_COUNT_ALL to copy the entire vector.] |
Return Type
Vvec_vector
New value vector
[This procedure creates a new vector that contains the elements in the original vector starting at position. A total of count elements are copied to the new vector.]
Example
/* Retain a copy of a vector being manipulated. */
Vvec_Vector copy_vector = op_vvec_copy (target_vector, OPC_VVEC_VECTOR_START,
OPC_VVEC_COUNT_ALL);
/* now change all characters in the target vector to upper case. */
for (i = 0; i < op_vvec_size_get (target_vector); i++)
{
/* Get current vector value */
op_vvec_value_get (target_vector, i, &c);
/* Modify if lower-case. */
if (islower (c))
c = toupper (c);
/* Modify target vector. */
op_vvec_value_set (target_vector, i, c);
}
/* copy_vector still contains original values in target_vector. */
Details
The vector that results from op_vvec_copy() can be assigned to a previously declared, but still undefined, vector. Alternatively, you can use this procedure to perform an operation on a copy of a value vector while leaving the original untouched.
For example, if the original vector contains the elements {1, 2, 3, 4, 5}, position is 1, and count is 3, op_vvec_copy() returns the following value vector:
- {2, 3, 4}
If, however, you use the same original vector with a position of 0 and a count of OPC_VVEC_COUNT_ALL, the following vector results:
- {1, 2, 3, 4, 5}
Purpose
Provide a way to duplicate value vectors.
Errors
- Recoverable Error: Value vector is invalid.
- Recoverable Error: Insufficient memory to copy (
<count>) values. - Recoverable Error: Values at positions (
<pos>) to (<pos>) could not be copied.
Reference
- Use the KP op_vvec_create() to create a new vector
- Use the KP op_vvec_insert() to place elements from one vector into another
- Use the KP op_vvec_remove() to create a new vector consisting of elements removed from another vector