1 /***************************************************************************
2 * Copyright (C) 2006 by Michael Andreen *
3 * andreen@student.chalmers.se *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
19 ***************************************************************************/
21 #include "componenttree.h"
26 ComponentTree::Node::Node(Node* parent, Component comp): _parent(parent), _comp(comp){
28 _parent->_children.push_back(this);
32 ComponentTree::Node::~Node(){
33 for (vector<Node*>::iterator c = _children.begin();
34 c != _children.end(); ++c){
39 ComponentTree::ComponentTree(const std::vector<Component>& components) : _root(0,Component()){
40 map<size_t,Component> starting;
41 map<size_t,Component> ending;
43 for (vector<Component>::const_iterator c = components.begin(); c != components.end(); ++c){
44 starting.insert(pair<size_t,Component>(c->i1,*c));
45 ending.insert(pair<size_t,Component>(c->i2,*c));
46 max = (c->i2 > max ? c->i2 : max);
50 Node* p = new Node(q,starting[0]);
52 for (size_t i = 1; i < max; ++i){
53 map<size_t,Component>::iterator c = starting.find(i);
54 if (c != starting.end()){
55 if (ending.find(i) == ending.end()){
56 q = new Node(p,Component());
58 p = new Node(q,c->second);
60 }else if (ending.find(i) != ending.end()){
68 ComponentTree::~ComponentTree(){