From 773c07332c97bfa475a658b8c75c0912c016d5ee Mon Sep 17 00:00:00 2001 From: scottmk Date: Thu, 10 Dec 2009 06:21:41 +0000 Subject: [PATCH] Add three new functions: osrfListSwap() -- swaps the contents of two osrfLists osrfStringArrayClear() -- renders an osrfStringArray empty osrfStringArraySwap() -- swaps the contents of two osrfStringArrays M include/opensrf/osrf_list.h M src/libopensrf/string_array.c M src/libopensrf/osrf_list.c git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1870 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_list.h | 2 ++ src/libopensrf/osrf_list.c | 19 +++++++++++++++++++ src/libopensrf/string_array.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/include/opensrf/osrf_list.h b/include/opensrf/osrf_list.h index 6f0ec6f..d1bde6a 100644 --- a/include/opensrf/osrf_list.h +++ b/include/opensrf/osrf_list.h @@ -90,6 +90,8 @@ void osrfListFree( osrfList* list ); void osrfListClear( osrfList* list ); +void osrfListSwap( osrfList* one, osrfList* two ); + void* osrfListRemove( osrfList* list, unsigned int position ); void* osrfListExtract( osrfList* list, unsigned int position ); diff --git a/src/libopensrf/osrf_list.c b/src/libopensrf/osrf_list.c index 6eff711..7ea3e97 100644 --- a/src/libopensrf/osrf_list.c +++ b/src/libopensrf/osrf_list.c @@ -191,6 +191,25 @@ void osrfListClear( osrfList* list ) { } /** + @brief Exchange the contents of two osrfLists. + @param one Pointer to the first osrfList. + @param two Pointer to the second osrfList. + + After the call, the first list contains what had been the contents of the second, + and vice versa. This swap also works if the two parameters point to the same + list; i.e. there is no net effect. + + If either parameter is NULL, nothing happens. +*/ +void osrfListSwap( osrfList* one, osrfList* two ) { + if( one && two ) { + osrfList temp = *one; + *one = *two; + *two = temp; + } +} + +/** @brief Remove the pointer from a specified position. @param list A pointer to the osrfList. @param position A zero-based index identifying the pointer to be removed. diff --git a/src/libopensrf/string_array.c b/src/libopensrf/string_array.c index 0194a28..be0b7d4 100644 --- a/src/libopensrf/string_array.c +++ b/src/libopensrf/string_array.c @@ -79,6 +79,37 @@ const char* osrfStringArrayGetString( const osrfStringArray* arr, int index ) { } /** + @brief Render an osrfStringArray empty. + @param arr Pointer to the osrfStringArray to be emptied. +*/ +void osrfStringArrayClear( osrfStringArray* arr ) { + if( arr ) { + osrfListClear( &arr->list ); + arr->size = 0; + } +} + +/** + @brief Exchange the contents of two osrfStringArrays. + @param one Pointer to the first osrfStringArray. + @param two Pointer to the second osrfStringArray. + + After the swap, the first osrfStringArray contains what had been the contents of the + second, and vice versa. The swap also works if both parameters point to the same + osrfStringArray; i.e. there is no net change. + + If either parameter is NULL, nothing happens. +*/ +void osrfStringArraySwap( osrfStringArray* one, osrfStringArray* two ) { + if( one && two ) { + osrfListSwap( &one->list, &two->list ); + int temp = one->size; + one->size = two->size; + two->size = temp; + } +} + +/** @brief Free an osrfStringArray, and all the strings inside it. @param arr Pointer to the osrfStringArray to be freed. */ -- 2.11.0