From d935b195a2246fa24d35df7c6fc354ae628a6777 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 10 Jan 2013 15:51:33 +0100 Subject: Added attributes to nodes as well as messages for manipulating and transporting them. Switched debug interface to hugin. --- src/tasktree.cc | 63 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 23 deletions(-) (limited to 'src/tasktree.cc') diff --git a/src/tasktree.cc b/src/tasktree.cc index e2e2bf6..b404cf5 100644 --- a/src/tasktree.cc +++ b/src/tasktree.cc @@ -27,9 +27,11 @@ */ #include "tasktree.h" +#include + #include "xmlparser.h" -#include "debug.h" +#include "hugin.hpp" #include "xml_encode_decode.h" @@ -47,7 +49,14 @@ std::string node::toXML(std::string prefix) std::string xml; xml += prefix + "\n"; - xml += prefix + " " + xml_encode(data.title) + "\n"; + xml += prefix + " \n"; + std::map::iterator ai = data.attributes.begin(); + while(ai != data.attributes.end()) { + xml += prefix + " first) + "\">" + + xml_encode(ai->second) + "\n"; + ai++; + } + xml += prefix + " \n"; xml += prefix + " \n"; NodeList::iterator ni = children.begin(); while(ni != children.end()) { @@ -78,7 +87,13 @@ TaskTree::~TaskTree() { } taskid_t TaskTree::createId() { - return nextid++; + taskid_t taskid; + + do { + taskid = nextid++; + } while(id2node.find(taskid) != id2node.end()); + + return taskid; } static taskid_t rootid = -1; @@ -102,7 +117,7 @@ TaskIdList TaskTree::insertAsChild(taskid_t parentid, taskid_t id, task_t data) try { node_t* parent = id2node.at(parentid); node_t* child = createNode(id); -// printf("!!!!!!!id in insert: %d\n", data.id); +// DEBUG(tasktree, "!!!!!!!id in insert: %d\n", data.id); child->data = data; insertChild(parent, child); @@ -116,7 +131,7 @@ TaskIdList TaskTree::insertAsChild(taskid_t parentid, taskid_t id, task_t data) } } -// printf("Child %d added to %d, affecting %d nodes\n", +// DEBUG(tasktree, "Child %d added to %d, affecting %d nodes\n", // id, parentid, affectedNodes.size()); return affectedNodes; } @@ -129,22 +144,22 @@ TaskIdList TaskTree::remove(taskid_t id) TaskIdList ancestors = ancestorList(id); concatTaskIdLists(affectedNodes, ancestors); -// printf("Removing %d\n", id); +// DEBUG(tasktree, "Removing %d\n", id); -// printf("!!!!!affected nodes %d\n", affectedNodes.size()); +// DEBUG(tasktree, "!!!!!affected nodes %d\n", affectedNodes.size()); node_t* node = id2node[id]; -// printf("node: %p, id %d, parent %p\n", node, node->data.id, node->parent); +// DEBUG(tasktree, "node: %p, id %d, parent %p\n", node, node->data.id, node->parent); -// printf("!!!!!size %d\n", node->parent->children.size()); +// DEBUG(tasktree, "!!!!!size %d\n", node->parent->children.size()); node->parent->children.remove(node); for(NodeList::iterator it = node->parent->children.begin(); it != node->parent->children.end(); it++) { -// printf("%p\n", *it); +// DEBUG(tasktree, "%p\n", *it); } -// printf("!!!!!size %d\n", node->parent->children.size()); +// DEBUG(tasktree, "!!!!!size %d\n", node->parent->children.size()); TaskIdList idlist = bfs(id); TaskIdList::reverse_iterator it = idlist.rbegin(); @@ -194,7 +209,8 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid) */ -TaskIdList TaskTree::updateData(taskid_t id, task_t t) +TaskIdList TaskTree::updateData(taskid_t id, const std::string &name, + const std::string &value) throw (std::exception) { @@ -202,7 +218,7 @@ TaskIdList TaskTree::updateData(taskid_t id, task_t t) try { node_t* node = id2node.at(id); - node->data = t; + node->data.attributes[name] = name; affectedNodes.push_back(id); TaskIdList ancestors = ancestorList(id); @@ -225,8 +241,8 @@ task_t TaskTree::data(taskid_t id) node_t* node = id2node.at(id); task_t tmp = node->data; t.id = node->id; - t.title = tmp.title; -// printf("!!!!t.id and tmp.id in data: %d and %d\n", t.id, tmp.id); + t.attributes["title"] = tmp.attributes["title"]; +// DEBUG(tasktree, "!!!!t.id and tmp.id in data: %d and %d\n", t.id, tmp.id); if(node->parent) t.parentid = node->parent->id; else { if(t.id != rootid) throw std::exception(); @@ -287,10 +303,10 @@ TaskIdList TaskTree::ancestorList(taskid_t id) throw e; } -// printf("Collected %d ancestors to %u\n", ancestors.size(), id); +// DEBUG(tasktree, "Collected %d ancestors to %u\n", ancestors.size(), id); // for(TaskIdList::iterator it = ancestors.begin(); // it != ancestors.end(); it++) { -// printf("\tancestor %u\n", *it); +// DEBUG(tasktree, "\tancestor %u\n", *it); // } return ancestors; } @@ -315,7 +331,8 @@ void TaskTree::insertChild(node_t* parent, node_t* child) { static void printNode(node_t* node, std::string prefix) { if(!node) return; task_t t = node->data; - printf("%s- %u - %s (%p)\n", prefix.c_str(), node->id, t.title.c_str(), node); + DEBUG(tasktree, "%s- %u - %s (%p)\n", prefix.c_str(), node->id, + t.attributes["title"].c_str(), node); NodeList::iterator it; for(it = node->children.begin(); it != node->children.end(); it++) { @@ -370,23 +387,23 @@ TEST_BEGIN; TaskTree tree; task_t t; -t.title = "root"; +t.attributes["title"] = "root"; t.id = ROOT_ID; tree.insertAsChild(0, ROOT_ID, t); -t.title = "Finished"; +t.attributes["title"] = "Finished"; t.id = FINISHED_ID; tree.insertAsChild(ROOT_ID, FINISHED_ID, t); -t.title = "Backlog"; +t.attributes["title"] = "Backlog"; t.id = BACKLOG_ID; tree.insertAsChild(ROOT_ID, BACKLOG_ID, t); -t.title = "Lost+Found"; +t.attributes["title"] = "Lost+Found"; t.id = LOSTFOUND_ID; tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t); -t.title = "Projects"; +t.attributes["title"] = "Projects"; t.id = PROJECTS_ID; tree.insertAsChild(ROOT_ID, PROJECTS_ID, t); -- cgit v1.2.3