/**
 * Push a object to the back of a LINKED_LIST
 * 
 * @param list the list to add the object too
 * @param object, the object that you are adding
 * @return -1 if unable to add due to memory errors, otherwise 0
 */
int ll_push_back(LINKED_LIST *list, void* object){
  LINKED_LIST_NODE *end_node;
  LINKED_LIST_NODE *new_node = ll_create_node(object);
  
  if(new_node == NULL){
    errno = ENOMEM;
    return -1;
  }
  
  if(list->size > 0){
    if(ll_get_node(list, list->size - 1, &end_node) == -1){
      errno = EINVAL;
      printf("Error: Unable to retrieve end node\n");
      return -1;
    }
    
    end_node->next = new_node;
    (list->size)++;
    return list->size - 1;
  }
  else{
    list->first_node = new_node;
    (list->size)++;
    return 0;
  }
}
Beispiel #2
0
rtobject_instance_t* rtobject_get_instance(const rtobject_t* rtobj, int pos){
  node_t* temp_node;

  if (!(temp_node = ll_get_node(&rtobj->instance_list, pos))){
    return 0;
  }

  return (rtobject_instance_t*)temp_node->data;
}
Beispiel #3
0
/*find the name of the node at a certain position*/
const char* ns_get_name(namespace_t *ns, int pos){
  node_t* temp_node;

  if (!(temp_node = ll_get_node(ns->members, pos))){
    return 0;
  }

  return ns->cb(temp_node);
}
Beispiel #4
0
scale_t* get_scale(int pos){
  node_t* temp_node;

  if (!(temp_node = ll_get_node(&scale_list, pos))){
    printf("get scale error: scale %d not found\n", pos);
    return 0;
  }

  return (scale_t*)temp_node->data;
}
/**
 * Get a object from a LINKED_LIST, will return the object as type void*
 * 
 * @param list the list to get the object off of
 * @param index, the index from where to get the object
 * @param object, the object to be returnd
 * @return -1 if unable to find, otherwise 0 if success
 */
int ll_get(LINKED_LIST *list, int index, void** object){
  LINKED_LIST_NODE *node;
  
  if(ll_get_node(list, index, &node) == -1){
    errno = EINVAL;
    *object = NULL;
    return -1;
  }
  
  else *object = node->object;
  return index;
}
Beispiel #6
0
int remove_scale(int pos){
  node_t* temp_node;

  if (!(temp_node = ll_get_node(&scale_list, pos))){
    printf("remove scale error: scale %d not found\n", pos);
    return 0;
  }

  ll_remove(temp_node, &scale_list);

  return 0;
}
/**
 * Remove an object from a linked list given the index
 * 
 * @param list the list to remove the object from
 * @param index, the index from where to remove the object
 * @param object, the object to be returnd
 * @return -1 if unable to find, otherwise 0 if success
 */
int ll_remove(LINKED_LIST *list, int index, void **object){
  LINKED_LIST_NODE *node, *prev_node;
  
  if(index < 0 || index >= list->size){
    errno = EINVAL;
    return -1;
  }

  if(index == 0){
    node = list->first_node;
    list->first_node = list->first_node->next;
    ll_free_node(list, node, object);
    (list->size)--;
    return index;
  }
  else{
    if(ll_get_node(list, index, &node) == -1){
      errno = EINVAL;
      if(object != NULL){
      	*object = NULL;
      }
      return -1;
    }
    if(ll_get_node(list, index - 1, &prev_node) == -1){
      errno = EINVAL;
      if(object != NULL){
      	*object = NULL;
      }
      return -1;
    }
    prev_node->next = node->next;
    ll_free_node(list, node, object);
    (list->size)--;
    return index;
  }  
  return 0;
}
Beispiel #8
0
/*
** 'id' represents the location where the user wishes to insert the node.
** if 'id' is greater than 0, the list will be traversed from the head.
** if 'id' is less than 0, the list will be traversed backwards (from the tail)
** 'id' 0 is invalid.
*/
int			ll_push_node(t_ll_list *list,
				     t_ll_node *node,
				     signed int id)
{
  t_ll_node		*w;

  if (!list || !node || id == 0)
    return (-1);
  if (list->count == 0 || id == 1 || (id * -1) > list->count)
    return (ll_push_node_head(list, node));
  else if (id == -1 || id > list->count)
    return (ll_push_node_tail(list, node));
  w = ll_get_node(list, id - (id > 0 ? 1 : 0));
  node->previous = w;
  node->next = w->next;
  w->next->previous = node;
  w->next = node;
  list->count += 1;
  return (0);
}
Beispiel #9
0
const control_t* rtobject_get_control(const rtobject_t* rtobj, int pos){
  node_t* temp_node;
  if (!(temp_node = ll_get_node(&rtobj->control_list, pos)))
    return 0;
  return (const control_t*)temp_node->data;
}