summaryrefslogtreecommitdiff
path: root/src/task.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/task.h')
-rw-r--r--src/task.h73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/task.h b/src/task.h
index 43541bc..5866719 100644
--- a/src/task.h
+++ b/src/task.h
@@ -30,6 +30,9 @@
#include <list>
#include <string>
+#include <stdio.h>
+#include <assert.h>
+//#include <queue>
/*
Task:
@@ -86,10 +89,78 @@ typedef struct {
} task_t;
-typedef std::list<task_t> TaskList;
+//typedef std::list<task_t> TaskList;
+
+class CompareByParentid {
+public:
+ bool operator()(const task_t &a, const task_t &b) const {
+ return a.parent_id < b.parent_id;
+ }
+};
+
+
+
+
+class TaskList : public std::list<task_t>{
+public:
+ TaskList() {}
+ ~TaskList(){}
+
+ void insert(task_t t) {
+ printf("inserting task %d with parent %d\n", t.id, t.parent_id);
+
+ if(t.parent_id == -1) {
+ std::list<task_t>::push_front(t);
+ return;
+ }
+
+ std::list<task_t>::iterator it;
+ for(it = begin(); it != end(); ++it) {
+ printf("\tcomparing %d and %d\n", t.parent_id, it->id);
+ if(t.parent_id == it->id) {
+ break;
+ }
+ }
+ assert(it != end());
+
+ std::list<task_t>::insert(++it, t);
+
+// std::list<task_t>::push_back(t);
+// std::list<task_t>::sort(CompareByParentid());
+
+ }
+
+ void move(task_t t) {
+ std::list<task_t>::iterator it;
+ for(it = begin(); it != end(); it++) {
+ if(t.id == it->id) {
+ break;
+ }
+ }
+ assert(it != end());
+ // if(it != end()) {
+ std::list<task_t>::erase(it);
+ // }
+ insert(t);
+ }
+
+ void push_back(task_t t) {
+ insert(t);
+ }
+
+private:
+ std::list<task_t> list;
+};
+
+
extern TaskList tasklist;
+//typedef std::priority_queue<task_t, std::vector<task_t>, CompareByParentid> TaskList;
+
task_t create_task(std::string title, std::string desc,
/*int x, int y*/ int parent_id);
+TaskList load_tasklist_from_file(std::string file);
+bool save_tasklist_to_file(TaskList t, std::string file);
+
#endif/*__MUNIA_TASK_H__*/