cgv
Loading...
Searching...
No Matches
group.cxx
1#include "group.h"
2#include <iostream>
3
4namespace cgv {
5 namespace base {
6
7group::group(const std::string& _name) : node(_name)
8{
9}
11{
12 node_ptr n = child->get_node();
13 if (n.empty())
14 return;
15 n->set_parent(node_ptr(this));
16}
18{
19 group_ptr g = child->get_group();
20 if(g.empty()) {
21 node_ptr n = child->get_node();
22 if(n.empty())
23 return;
24 n->set_parent(node_ptr());
25 } else {
26 g->remove_all_children();
27 }
28}
29unsigned int group::get_nr_children() const
30{
31 return (unsigned int) children.size();
32}
33base_ptr group::get_child(unsigned int i) const
34{
35 if (i >= children.size()) {
36 std::cerr << "group " << get_name() << ":" << get_type_name() << " -> attempt to access child at " << i << " what is after last valid location " << children.size()-1 << std::endl;
37 return base_ptr();
38 }
39 return children[i];
40}
42{
43 children.push_back(child);
44 link(child);
45 return get_nr_children()-1;
46}
48{
49 unsigned int i, nr_removed = 0;
50 for (i=0; i<children.size(); ++i) {
51 if (children[i] == child) {
52 ++nr_removed;
53 children.erase(children.begin()+i);
54 --i;
55 }
56 }
58 return nr_removed;
59}
61{
62 for (unsigned int i=0; i<children.size(); ++i)
64 children.clear();
65}
67{
68 if (i > children.size()) {
69 std::cerr << "attempt to insert child at " << i << " what is after last valid location " << children.size() << std::endl;
70 return;
71 }
72 if (i == children.size())
73 children.push_back(child);
74 else
75 children.insert(children.begin()+i, child);
76 link(child);
77}
79{
80 return group_ptr(this);
81}
86std::string group::get_type_name() const
87{
88 return "group";
89}
90
91 }
92}
group(const std::string &name="")
construct from name
Definition group.cxx:7
std::vector< base_ptr > children
store a list of children
Definition group.h:25
virtual void insert_child(unsigned int i, base_ptr child)
insert a child at the given position
Definition group.cxx:66
group_ptr get_group()
cast upward to group
Definition group.cxx:78
virtual void remove_all_children()
remove all children
Definition group.cxx:60
void unlink(base_ptr b)
check if the base class is a node and clear the parent of the node
Definition group.cxx:17
unsigned int get_nr_children() const
return the number of children
Definition group.cxx:29
std::string get_type_name() const
overload to return the type name of this object
Definition group.cxx:86
base_ptr get_child(unsigned int i) const
return the i-th child
Definition group.cxx:33
const_group_ptr get_group_const()
cast upward to const group
Definition group.cxx:82
void link(base_ptr b)
check if the base class is a node and set the parent of the node
Definition group.cxx:10
virtual unsigned int remove_child(base_ptr child)
remove all elements of the vector that point to child, return the number of removed children
Definition group.cxx:47
virtual unsigned int append_child(base_ptr child)
append child and return index of appended child
Definition group.cxx:41
const std::string & get_name() const
return the parent node
Definition named.cxx:9
The node class keeps a pointer to its parent.
Definition node.h:19
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
bool empty() const
check if pointer is not yet set
Definition ref_ptr.h:230
data::ref_ptr< const group, true > const_group_ptr
ref counted pointer to a node
Definition group.h:16
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
Definition base.h:37
data::ref_ptr< node, true > node_ptr
ref counted pointer to a node
Definition node.h:13
data::ref_ptr< group, true > group_ptr
ref counted pointer to a node
Definition group.h:14
the cgv namespace
Definition print.h:11