goat3d
diff src/node.cc @ 8:cd71f0b92f44
a bit more...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 21 Aug 2013 05:52:28 +0300 |
parents | 2918358f5e6d |
children | 498ca7ac7047 |
line diff
1.1 --- a/src/node.cc Wed Aug 21 04:00:22 2013 +0300 1.2 +++ b/src/node.cc Wed Aug 21 05:52:28 2013 +0300 1.3 @@ -4,92 +4,28 @@ 1.4 1.5 Node::Node() 1.6 { 1.7 - parent = 0; 1.8 + obj = 0; 1.9 } 1.10 1.11 -Node::~Node() 1.12 +void Node::set_object(Object *obj) 1.13 { 1.14 + this->obj = obj; 1.15 } 1.16 1.17 -void Node::set_name(const char *name) 1.18 +Object *Node::get_object() 1.19 { 1.20 - this->name = name; 1.21 + return obj; 1.22 } 1.23 1.24 -const char *Node::get_name() const 1.25 +const Object *Node::get_object() const 1.26 { 1.27 - return name.c_str(); 1.28 + return obj; 1.29 } 1.30 1.31 -void Node::add_child(Node *c) 1.32 +void delete_node_tree(Node *n) 1.33 { 1.34 - // make sure we don't add it twice 1.35 - if(std::find(children.begin(), children.end(), c) != children.end()) { 1.36 - return; 1.37 + for(int i=0; i<n->get_children_count(); i++) { 1.38 + delete_node_tree((Node*)n->get_child(i)); 1.39 } 1.40 - children.push_back(c); 1.41 - c->parent = this; 1.42 + delete n; 1.43 } 1.44 - 1.45 -int Node::get_num_children() const 1.46 -{ 1.47 - return (int)children.size(); 1.48 -} 1.49 - 1.50 -Node *Node::get_child(int idx) const 1.51 -{ 1.52 - if(idx < 0 || idx >= get_num_children()) { 1.53 - return 0; 1.54 - } 1.55 - return children[idx]; 1.56 -} 1.57 - 1.58 -Node *Node::get_child(const char *name) const 1.59 -{ 1.60 - for(size_t i=0; i<children.size(); i++) { 1.61 - if(strcmp(children[i]->get_name(), name) == 0) { 1.62 - return children[i]; 1.63 - } 1.64 - } 1.65 - return 0; 1.66 -} 1.67 - 1.68 -Node *Node::get_descendant(const char *name) const 1.69 -{ 1.70 - Node *c = get_child(name); 1.71 - if(c) { 1.72 - return c; 1.73 - } 1.74 - 1.75 - // depth first search might not be ideal in this case, but it's the simplest 1.76 - for(size_t i=0; i<children.size(); i++) { 1.77 - if((c = children[i]->get_descendant(name))) { 1.78 - return c; 1.79 - } 1.80 - } 1.81 - return 0; 1.82 -} 1.83 - 1.84 -Node *Node::get_parent() const 1.85 -{ 1.86 - return parent; 1.87 -} 1.88 - 1.89 -Node *Node::get_ancestor(const char *name) const 1.90 -{ 1.91 - Node *n = (Node*)this; 1.92 - 1.93 - if(!name) { 1.94 - // just return the root 1.95 - while(n->parent) { 1.96 - n = n->parent; 1.97 - } 1.98 - return n; 1.99 - } 1.100 - 1.101 - // otherwise we're looking for a specific ancestor 1.102 - while(n && strcmp(n->get_name(), name) != 0) { 1.103 - n = n->parent; 1.104 - } 1.105 - return n; 1.106 -}