| 101 | | /* Allocate room for the new object */ |
|---|
| 102 | | if ( nCount < nPosition ) |
|---|
| 103 | | { |
|---|
| 104 | | for ( i = nCount; i < nPosition - 1; i++ ) |
|---|
| 105 | | CPLListAppend( psList, NULL ); |
|---|
| 106 | | CPLListAppend( psList, pData ); |
|---|
| | 101 | if ( nPosition == 0) |
|---|
| | 102 | { |
|---|
| | 103 | CPLList *psNew = (CPLList *)CPLMalloc( sizeof(CPLList) ); |
|---|
| | 104 | psNew->pData = pData; |
|---|
| | 105 | psNew->psNext = psList; |
|---|
| | 106 | psList = psNew; |
|---|
| | 107 | } |
|---|
| | 108 | else if ( nCount < nPosition ) |
|---|
| | 109 | { |
|---|
| | 110 | /* Allocate room for the new object */ |
|---|
| | 111 | CPLList* psLast = CPLListGetLast(psList); |
|---|
| | 112 | for ( i = nCount; i <= nPosition - 1; i++ ) |
|---|
| | 113 | { |
|---|
| | 114 | psLast = CPLListAppend( psLast, NULL ); |
|---|
| | 115 | if (psList == NULL) |
|---|
| | 116 | psList = psLast; |
|---|
| | 117 | else |
|---|
| | 118 | psLast = psLast->psNext; |
|---|
| | 119 | } |
|---|
| | 120 | psLast = CPLListAppend( psLast, pData ); |
|---|
| | 121 | if (psList == NULL) |
|---|
| | 122 | psList = psLast; |
|---|
| 226 | | |
|---|
| 227 | | psCurrent = psList; |
|---|
| 228 | | for ( i = 0; i < nPosition - 1; i++ ) |
|---|
| 229 | | psCurrent = psCurrent->psNext; |
|---|
| 230 | | psRemoved = psCurrent->psNext; |
|---|
| 231 | | psCurrent->psNext = psRemoved->psNext; |
|---|
| 232 | | CPLFree( psRemoved ); |
|---|
| | 245 | } |
|---|
| | 246 | else if ( nPosition == 0 ) |
|---|
| | 247 | { |
|---|
| | 248 | psCurrent = psList->psNext; |
|---|
| | 249 | CPLFree( psList ); |
|---|
| | 250 | psList = psCurrent; |
|---|
| | 251 | } |
|---|
| | 252 | else |
|---|
| | 253 | { |
|---|
| | 254 | psCurrent = psList; |
|---|
| | 255 | for ( i = 0; i < nPosition - 1; i++ ) |
|---|
| | 256 | { |
|---|
| | 257 | psCurrent = psCurrent->psNext; |
|---|
| | 258 | /* psCurrent == NULL if nPosition >= CPLListCount(psList) */ |
|---|
| | 259 | if (psCurrent == NULL) |
|---|
| | 260 | return psList; |
|---|
| | 261 | } |
|---|
| | 262 | psRemoved = psCurrent->psNext; |
|---|
| | 263 | /* psRemoved == NULL if nPosition >= CPLListCount(psList) */ |
|---|
| | 264 | if (psRemoved == NULL) |
|---|
| | 265 | return psList; |
|---|
| | 266 | psCurrent->psNext = psRemoved->psNext; |
|---|
| | 267 | CPLFree( psRemoved ); |
|---|
| | 268 | } |
|---|