cgv
Loading...
Searching...
No Matches
group.h
1#pragma once
2
3#include "node.h"
4#include <vector>
5
6#include "lib_begin.h"
7
8namespace cgv {
9 namespace base {
10
11class CGV_API group;
12
17
19class CGV_API group : public node
20{
21protected:
23 friend class data::ref_ptr<group,true>;
25 std::vector<base_ptr> children;
27 void link(base_ptr b);
29 void unlink(base_ptr b);
30public:
32 group(const std::string& name = "");
34 unsigned int get_nr_children() const;
36 base_ptr get_child(unsigned int i) const;
38 template<typename T>
39 data::ref_ptr<T> create_and_append_child(const std::string& name = "", unsigned int* index = nullptr) {
40 static_assert(std::is_base_of<node, T>::value, "T must inherit from node");
41 data::ref_ptr<T> ptr(new T());
42 ptr->set_name(name);
43 unsigned int i = append_child(ptr);
44 if(index)
45 *index = i;
46 return ptr;
47 }
49 virtual unsigned int append_child(base_ptr child);
51 virtual unsigned int remove_child(base_ptr child);
53 virtual void remove_all_children();
55 virtual void insert_child(unsigned int i, base_ptr child);
57 group_ptr get_group();
59 const_group_ptr get_group_const();
61 std::string get_type_name() const;
62};
63
64template <> struct cast_helper<group>
65{
66 inline static group_ptr cast(base* b) { return b->get_group(); }
67};
68template <> struct cast_const_helper<group>
69{
70 inline static const_group_ptr cast_const(const base* b) { return b->get_group_const(); }
71};
72
73
74#if _MSC_VER >= 1400
75CGV_TEMPLATE template class CGV_API data::ref_ptr<group>;
76CGV_TEMPLATE template class CGV_API std::vector<base_ptr>;
77#endif
78
79 }
80}
81
82#include <cgv/config/lib_end.h>
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
The group class is a node with children.
Definition group.h:20
data::ref_ptr< T > create_and_append_child(const std::string &name="", unsigned int *index=nullptr)
create and append an instance of a child node and return pointer to appended child; optionally set na...
Definition group.h:39
std::vector< base_ptr > children
store a list of children
Definition group.h:25
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
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
data::ref_ptr< const group, true > const_group_ptr
ref counted pointer to a node
Definition group.h:16
data::ref_ptr< group, true > group_ptr
ref counted pointer to a node
Definition group.h:14
the cgv namespace
Definition print.h:11