IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8804


Ignore:
Timestamp:
Sep 12, 2006, 11:55:49 AM (20 years ago)
Author:
jhoblitt
Message:

add psArrayRemoveByPos()

Location:
trunk/psLib/src/types
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psArray.c

    r8799 r8804  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2006-09-12 21:08:15 $
     11 *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-09-12 21:55:49 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psArray.h"
    2828#include "psLogMsg.h"
     29#include "psAssert.h"
    2930
    3031
     
    158159}
    159160
     161bool psArrayRemoveByPos(psArray* array,
     162                        long position)
     163{
     164    PS_ASSERT_PTR_NON_NULL(array, false);
     165
     166    if (position > array->n) {
     167        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     168                _("position > then the number of elements in the array."));
     169        return false;
     170    }
     171
     172    long i = position;
     173    long n = array->n;
     174    psFree(array->data[i]);
     175    memmove(&array->data[i], &array->data[i + 1], (n - i - 1) * sizeof(psPtr));
     176    array->n = --i; // reset the array size to indicate the removed item(s)
     177
     178    return true;
     179}
     180
    160181void psArrayElementsFree(psArray* array)
    161182{
  • trunk/psLib/src/types/psArray.h

    r8798 r8804  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-09-12 21:04:11 $
     13 *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-09-12 21:55:49 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9797);
    9898
    99 /** Remove an element from the array
     99/** Remove an element from the array by it's pointer
    100100 *
    101101 *  Finds and removes the specified data pointer from the list.
     
    108108    psArray* array,                    ///< array to operate on
    109109    const psPtr data                   ///< the data pointer to remove from psArray
     110);
     111
     112/** Remove an element from the array
     113 *
     114 *  Finds and removes the elements as the specified position
     115 *
     116 * @return bool:  TRUE if the specified data pointer was found and removed,
     117 *                otherwise FALSE.
     118 *
     119 */
     120bool psArrayRemoveByPos(
     121    psArray* array,                    ///< array to operate on
     122    long position                      ///< the element to remove
    110123);
    111124
  • trunk/psLib/src/types/psMetadataConfig.c

    r8794 r8804  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.84 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-09-12 04:18:56 $
     12*  @version $Revision: 1.85 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-09-12 21:55:49 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    11181118                } else {
    11191119                    // Remove lower info level
    1120                     if(!psArrayRemove(levelArray,levelArray->data[*level])) {
     1120                    if(!psArrayRemoveByPos(levelArray, *level)) {
    11211121                        psFree(keyName);
    11221122                        return false;
Note: See TracChangeset for help on using the changeset viewer.