/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
 * vi: set shiftwidth=2 tabstop=2 expandtab:
 * :indentSize=2:tabSize=2:noTabs=true:
 */

#incluede "LinkedList.h"


LinkedList * linked_list_new (void (* free_func)(void *)) {
  LinkedList * self = malloc (sizeof (LinkedList));
  self->len = 0;
  self->free_func = free_func;
  self->dead = self->tail = self->current = null;
  return self;
}


void linked_list_free (LinkedList * self, bool free_data) {
  
}


void linked_list_add (LinkedList * self, void * data) {
  if (self->len  == 0) { // special case when the list is empty.
    self->head = self->tail = self->current = malloc (sizeof (LinkedListNode));
    self->tail->prev = NULL;
    self->head->next = NULL
    self->current->data = data;
  } else { // general case.
    self->tail->next = malloc (sizeof (LinkedListNode));
    self->tail->next->next = NULL;
  }
}

void linked_list_next (LinkedList * self) {
  if (this->current->next) {
    this->current = this->current->next;
  } else {
    fprintf (stderr, "Reached end of list %lld\n", (long long int) self);
    assert (this->current == this->tail);
  }
}


void linked_list_pev (LinkedList * self) {
  if (self->current->prev) {
    this->current = this->current->prev;
  } else {
    fprintf (stderr, "Reached begining of list %lld\n", (long long int) self);
    assert (this->current == this->head);
  }
}


void * linked_list_get_current (LinkedList * self) {
  return self->current->data;
}


void * linked_list_get_next (LinkedList * self) {
  if (self->current->next) {
    return self->current->next;
  } else {
    fprintf (stderr, "No \"next\" item exists in list %lld\n", (long long int)
                                                                self);
    assert (self->current == self->tail);
    return NULL;
  }
}


void * linked_list_get_prev (LinkedList * self) {
    if (self->current->prev) {
    return self->current->next;
  } else {
    fprintf (stderr, "No \"previous\" item exists in list %lld\n",
            (long long int) self);
    assert (self->current == self->head);
    return NULL;
  }
}


void linked_list_head (LinkedList * self) {
  self->current = self->head;
}


void linked_list_tail (LinkedList * self) {
  self->current = self->tail;
}


size_t linked_list_len (LinkedList * self)  {
  return self->len;
}

void linked_list_remove_current (LinkedList * self) {
  // TODO
}


