示例#1
0
void removeFromByKey(Item* itemsList, char* key)
{
    assert(isItemInList(itemsList, key));
    
    bool foundKeyIndex = false;
    int keyIndex       = 0;
    
    while (! foundKeyIndex) // Establish where the item is
    {
        keyIndex++;
        
        if (itemsList[keyIndex].key == key)
        {
            foundKeyIndex = true;
        }
    }
    
    for (int i = keyIndex; i <= (itemsList[0].META.int_Meta - 2); i++) // '-2' to skip meta... and the index to be removed
    {
        itemsList[i] = itemsList[i + 1];
    }

    itemsList[0].META.int_Meta--; // Now one less item in the Dictionary
    
    Item* tempElements = realloc(itemsList, ((itemsList[0].META.int_Meta) *
                                             sizeof(Item))); // Make memory heap one Item- size smaller
    
    assert(tempElements != NULL);
    
    itemsList = tempElements;
}
示例#2
0
/*************************************************************************
    Handler for when list content has changed
*************************************************************************/
void ComboDropList::onViewContentsChanged(WindowEventArgs& e)
{
    // basically see if our 'sticky' selection was removed
    if ((d_lastItemSelected) && !isItemInList(d_lastItemSelected))
        d_lastItemSelected = 0;

    // base class processing
    ListWidget::onViewContentsChanged(e);
}
示例#3
0
void addTo(Item* itemsList, char* key, int value)
{
    assert(! isItemInList(itemsList, key)); // Make sure the key is not already in the list
    
    Item* tempElements = realloc(itemsList, ((itemsList[0].META.int_Meta + 1) *
                                             sizeof(Item)));
                                 
    assert(tempElements != NULL);
    
    itemsList                             = tempElements;
    Item newItem                          = {key, value};
    itemsList[itemsList[0].META.int_Meta] = newItem;

    itemsList[0].META.int_Meta++; // Increment the number of elements in the array
}
示例#4
0
Item getItemAtKey(Item* itemsList, char* key)
{
    assert(isItemInList(itemsList, key));
    
    Item itemToReturn;
    
    for (int i = 1; i <= (itemsList[0].META.int_Meta - 1); i++)
    {
        if (itemsList[i].key == key)
        {
            itemToReturn = itemsList[i];
        }
    }
    
    return itemToReturn;
}
示例#5
0
void removeHeadList(LinkedList **listPtr, LinkedList *listToRemove) {
  LinkedList *head = *listPtr, *currentPtr = *listPtr;
  LinkedList *removeList, *tempList;
  
  if(head == NULL)  {
    //printf("List is empty\n");
    return;
  }
  
  //listToRemove at head
  else  {
    if(isItemInList(&currentPtr, listToRemove->data)) {
      tempList = (*listPtr)->next;
      *listPtr = tempList;
      return;
    }
  }
}
示例#6
0
void removeLinkedList(LinkedList **listPtr, LinkedList *listToRemove) {
  LinkedList *currentPtr = *listPtr;
  LinkedList *removeList, *tempList;
  
  removeHeadList(listPtr, listToRemove);
  
  if((*listPtr) == NULL)
    return;
  
  currentPtr = *listPtr; //update currentPtr
  
  //listToRemove at body/tail
  removeList = currentPtr->next;
  while(removeList != NULL) {
    if(isItemInList(&removeList, listToRemove->data))  {
      tempList = removeList->next;
      currentPtr->next = tempList;
      return;
    }
    currentPtr = currentPtr->next;
    removeList = removeList->next;
  }
}
示例#7
0
void cBuildingList::addItemToList(cBuildingListItem * item) {
	assert(item);

	if (isItemInList(item)) {
		logbook("Failed to add icon to cBuildingList, item is already in list.");
		// item is already in list, do not add
		return;
	}

	int slot = getFreeSlot();
	if (slot < 0) {
		logbook("Failed to add icon to cBuildingList, no free slot left in list");
		assert(false);
		return;
	}

	// add
	items[slot] = item;
	item->setSlotId(slot);
	maxItems = slot;
	//	char msg[355];
	//	sprintf(msg, "Icon added with id [%d] added to cBuilding list, put in slot[%d], set maxItems to [%d]", item->getBuildId(), slot, maxItems);
	//	logbook(msg);
}