From f7dc7c17af52e8300cb188c4fb3e4a8b1638e8f9 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Thu, 22 Mar 2012 16:31:28 +0100 Subject: Fixed order of task in init. Now are tasks only (hopefully) added after its parent. Added write and read. --- src/task.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'src/task.h') 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 #include +#include +#include +//#include /* Task: @@ -86,10 +89,78 @@ typedef struct { } task_t; -typedef std::list TaskList; +//typedef std::list 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{ +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::push_front(t); + return; + } + + std::list::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::insert(++it, t); + +// std::list::push_back(t); +// std::list::sort(CompareByParentid()); + + } + + void move(task_t t) { + std::list::iterator it; + for(it = begin(); it != end(); it++) { + if(t.id == it->id) { + break; + } + } + assert(it != end()); + // if(it != end()) { + std::list::erase(it); + // } + insert(t); + } + + void push_back(task_t t) { + insert(t); + } + +private: + std::list list; +}; + + extern TaskList tasklist; +//typedef std::priority_queue, 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__*/ -- cgit v1.2.3