TutPtrAryReplaceItemAtIndex


Name

TutPtrAryReplaceItemAtIndex — replace an item in a pointer array at the specified index with a new one

Synopsis

T_BOOL TutPtrAryReplaceItemAtIndex(ptr_ary, new_item, index, old_item_return) 
T_PTR_ARY ptr_ary; 
T_PTR new_item; 
T_INt4 index; 
T_PTR *old_item_return; 

Arguments

ptr_ary — pointer array to operate on.

new_item — new item to put in the array.

index — location in the array where the item is put.

old_item_return — pointer to optional item currently stored in the array at the specified location. This argument may be NULL.

Return Values

TRUE if operation is a success, FALSE otherwise.

Diagnostics

None

Description

TutPtrAryReplaceItemAtIndex replaces the element stored in the array at the specified index with the new element. Old element is returned in the optional old_item_return argument. The function returns FALSE if the specified index is less than zero or greater than the total number of elements in the array minus one.

TutPtrAryReplaceItemAtIndex calls the pointer array change callbacks with the reason T_PA_ITEM_REPLACED.

Caution

TutPtrAryReplaceItemAtIndex does not free the item replaced in the array.

See Also

TutPtrAryInsertItemAtIndex

Examples

This example replaces an item in the pointer array:

T_PTR_ARY ptr_ary; 
T_INT4 i, *int_ptr, *new_ptr; 
/* create the pointer array with initial size of 30 */ 
 
ptr_ary = TutPtrAryCreate(30); 
/* fill it up with 25 entries */ 
for (i = 0; i < 25; i++) { 
  /* allocate the space for the next element */ 
  T_MALLOC(int_ptr, sizeof(T_INT4), T_INT4 *); 
  *int_ptr = i; 
  /* append the item to the array, ignore the index */ 
  TutPtrAryAppend(ptr_ary, int_ptr, NULL); 
}  
 
T_MALLOC(new_ptr, sizeof(T_INT4), T_INT4 *); 
*new_ptr = 169; 
 
/* Replace the item at index 13 with the new one */ 
TutPtrAryReplaceItemAtIndex(ptr_ary, new_ptr, 13,  
                            (T_PTR *)&int_ptr); 

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com