summaryrefslogtreecommitdiff
path: root/Source/Kernel/Library
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-11 17:28:45 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-11 17:28:45 +0200
commit244df8bd2c52db9d9c9b59b917206dafcd275ebe (patch)
tree27aefa8ff8373bcb674bb2c4820e136c41232d16 /Source/Kernel/Library
parent5b9f35ec7509e169f58500b66712eafb075d0b36 (diff)
downloadMelon-244df8bd2c52db9d9c9b59b917206dafcd275ebe.tar.gz
Melon-244df8bd2c52db9d9c9b59b917206dafcd275ebe.zip
Added a single linked list simple class (SimpleList)
Diffstat (limited to 'Source/Kernel/Library')
-rw-r--r--Source/Kernel/Library/SimpleList.class.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/Source/Kernel/Library/SimpleList.class.h b/Source/Kernel/Library/SimpleList.class.h
new file mode 100644
index 0000000..c0ea111
--- /dev/null
+++ b/Source/Kernel/Library/SimpleList.class.h
@@ -0,0 +1,54 @@
+#ifndef DEF_SIMPLELIST_CLASS_H
+#define DEF_SIMPLELIST_CLASS_H
+
+/* This class implements a singly linked list. It is also used to represent one of its elements. */
+
+template <typename T>
+class SimpleList {
+ protected:
+ T m_value;
+ SimpleList<T>* m_next;
+
+ public:
+ SimpleList(const T& value, SimpleList<T>* next = 0) : m_value(value), m_next(next) {}
+ ~SimpleList() {
+ if (m_next != 0)
+ delete m_next;
+ }
+
+ T& v() { return m_value; }
+ T& operator* () { return m_value; }
+
+ SimpleList<T>* cons(const T& value) {
+ return new SimpleList<T>(value, this);
+ }
+
+ SimpleList<T>* next() {
+ return m_next;
+ }
+
+ SimpleList<T>* delThis() {
+ SimpleList<T>* ret = m_next;
+ Mem::kfree(this);
+ return ret;
+ }
+
+ void delNext() {
+ if (m_next == 0) return;
+ SimpleList<T>* temp = m_next;
+ m_next = m_next->m_next;
+ Mem::kfree(temp);
+ }
+
+ bool isEnd() {
+ return m_next == 0;
+ }
+
+ u32int size() {
+ if (m_next == 0)
+ return 0;
+ return m_next->size() + 1;
+ }
+};
+
+#endif