Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PObject * PAbstractList::RemoveAt ( PINDEX  index ) [virtual]

Remove the object at the specified ordinal index from the collection. If the AllowDeleteObjects option is set then the object is also deleted.

Note if the index is beyond the size of the collection then the function will assert.

Returns:
pointer to the object being removed, or NULL if it was deleted.
Parameters:
indexIndex position in collection to place the object.

Implements PCollection.

Definition at line 607 of file collect.cxx.

References SetCurrent().

Referenced by Remove().

{
  if (!SetCurrent(index)) {
    PAssertAlways(PInvalidArrayIndex);
    return NULL;
  }

  if(info == NULL){
    PAssertAlways("info is null");
    return NULL;
  }
    
  Element * elmt = info->lastElement;

  if(elmt == NULL){
    PAssertAlways("elmt is null");
    return NULL;
  }
  
  if (elmt->prev != NULL)
    elmt->prev->next = elmt->next;
  else {
    info->head = elmt->next;
    if (info->head != NULL)
      info->head->prev = NULL;
  }

  if (elmt->next != NULL)
    elmt->next->prev = elmt->prev;
  else {
    info->tail = elmt->prev;
    if (info->tail != NULL)
      info->tail->next = NULL;
  }

  if (elmt->next != NULL)
    info->lastElement = elmt->next;
  else {
    info->lastElement = elmt->prev;
    info->lastIndex--;
  }
  
  if((reference == NULL) || (reference->size == 0)){
    PAssertAlways("reference is null or reference->size == 0");
    return NULL;
  }
  reference->size--;

  PObject * obj = elmt->data;
  if (obj != NULL && reference->deleteObjects) {
    delete obj;
    obj = NULL;
  }
  delete elmt;
  return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index