libsaria: Remove my custom linked list class
Now that I'm using vectors for everything I don't need to maintain my own class. Nothing uses it now, so it can be safely removed. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
36e9995bb9
commit
b6e0d6dd58
|
@ -2,7 +2,6 @@
|
|||
#define LIBSARIA_LIBRARY_H
|
||||
|
||||
#include <fs.h>
|
||||
#include <list.h>
|
||||
#include <track.h>
|
||||
#include <playlist.h>
|
||||
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
#ifndef LIBSARIA_LIST_H
|
||||
#define LIBSARIA_LIST_H
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
template <class T>
|
||||
class List;
|
||||
|
||||
template <class T>
|
||||
class ListItem {
|
||||
friend class List<T>;
|
||||
private:
|
||||
ListItem *prev_item;
|
||||
ListItem *next_item;
|
||||
List<T> *list;
|
||||
T value;
|
||||
|
||||
public:
|
||||
ListItem();
|
||||
ListItem(T, List<T> *, ListItem<T> *, ListItem<T> *);
|
||||
~ListItem();
|
||||
T &get_value();
|
||||
ListItem<T> *next();
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class List {
|
||||
private:
|
||||
unsigned int count;
|
||||
ListItem<T> head;
|
||||
|
||||
public:
|
||||
List();
|
||||
List(const List<T> &);
|
||||
~List();
|
||||
|
||||
ListItem<T> *push_front(T);
|
||||
ListItem<T> *push_back(T);
|
||||
T pop_front();
|
||||
|
||||
ListItem<T> *erase(ListItem<T> *);
|
||||
unsigned int size();
|
||||
|
||||
ListItem<T> *first();
|
||||
ListItem<T> *end();
|
||||
|
||||
void for_each_item(void (*)(T &, void *), void *);
|
||||
ListItem<T> *find_item(bool (*)(T &, void *), void *);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#include "../libsaria/list/node.cpp"
|
||||
#include "../libsaria/list/list.cpp"
|
||||
|
||||
#endif /* LIBSARIA_LIST_H */
|
|
@ -4,7 +4,6 @@
|
|||
#include <track.h>
|
||||
#include <print.h>
|
||||
#include <deck.h>
|
||||
#include <list.h>
|
||||
#include <idle.h>
|
||||
#include <fs.h>
|
||||
#include "library.h"
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#ifndef LIBSARIA_LIST_CPP
|
||||
#define LIBSARIA_LIST_CPP
|
||||
|
||||
#include <list.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
template <class T>
|
||||
List<T>::List()
|
||||
{
|
||||
count = 0;
|
||||
head.list = this;
|
||||
}
|
||||
|
||||
/*
|
||||
* This just claims to be a copy constructor.
|
||||
* A real one should be implemented later if it's needed
|
||||
*/
|
||||
template <class T>
|
||||
List<T>::List(const List<T> &orig)
|
||||
{
|
||||
count = 0;
|
||||
head.list = this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
List<T>::~List()
|
||||
{
|
||||
while (count > 0)
|
||||
erase(head.next_item);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T> *List<T>::push_front(T item)
|
||||
{
|
||||
ListItem<T> *node;
|
||||
node = new ListItem<T>(item, this, &head, first());
|
||||
count++;
|
||||
return node;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T> *List<T>::push_back(T item)
|
||||
{
|
||||
ListItem<T> *node;
|
||||
node = new ListItem<T>(item, this, head.prev_item, &head);
|
||||
count++;
|
||||
return node;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T List<T>::pop_front()
|
||||
{
|
||||
T item;
|
||||
if (count == 0)
|
||||
item = head.value;
|
||||
else {
|
||||
item = first()->value;
|
||||
erase(first());
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T> *List<T>::erase(ListItem<T> *node)
|
||||
{
|
||||
ListItem<T> *prev = node->prev_item;
|
||||
ListItem<T> *next = node->next_item;
|
||||
|
||||
prev->next_item = next;
|
||||
next->prev_item = prev;
|
||||
count--;
|
||||
delete node;
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unsigned int List<T>::size()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T> *List<T>::first()
|
||||
{
|
||||
return head.next_item;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T> *List<T>::end()
|
||||
{
|
||||
return &head;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void List<T>::for_each_item(void (*func)(T &, void *), void *data)
|
||||
{
|
||||
for (ListItem<T> *it = first(); it != end(); it = it->next())
|
||||
func(it->value, data);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T> *List<T>::find_item(bool (*func)(T &, void *), void *data)
|
||||
{
|
||||
ListItem<T> *it;
|
||||
for (it = first(); it != end(); it = it->next()) {
|
||||
if (func(it->value, data))
|
||||
return it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* LIBSARIA_LIST_CPP */
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#ifndef LIBSARIA_NODE_CPP
|
||||
#define LIBSARIA_NODE_CPP
|
||||
|
||||
#include <list.h>
|
||||
#include <cstddef>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
template <class T>
|
||||
ListItem<T>::ListItem()
|
||||
{
|
||||
prev_item = this;
|
||||
next_item = this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T>::ListItem(T val, List<T> *lst, ListItem<T> *a, ListItem<T> *b)
|
||||
{
|
||||
list = lst;
|
||||
value = val;
|
||||
|
||||
a->next_item = this;
|
||||
prev_item = a;
|
||||
next_item = b;
|
||||
b->prev_item = this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T>::~ListItem()
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T &ListItem<T>::get_value()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ListItem<T> *ListItem<T>::next()
|
||||
{
|
||||
return next_item;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* LIBSARIA_NODE_CPP */
|
Loading…
Reference in New Issue