cgv
Loading...
Searching...
No Matches
base.h
1#pragma once
2
3#include <cgv/type/info/type_name.h>
4#include <cgv/reflect/reflection_handler.h>
5#include <cgv/data/ref_ptr.h>
6#include <iostream>
7
8#include <cgv/type/lib_begin.h>
9
10namespace cgv {
11 namespace type {
12 namespace info {
13
14struct CGV_API type_interface;
15
18
19 }
20 }
21}
22#include <cgv/config/lib_end.h>
23
24#include "lib_begin.h"
25
27namespace cgv {
29 namespace base {
30
31class CGV_API base;
32class CGV_API named;
33class CGV_API node;
34class CGV_API group;
35
38
41
43{
44 template <class T>
45 static data::ref_ptr<T,true> cast_of_base(base* b);
46};
47
48template <class T>
50{
51 inline static data::ref_ptr<T,true> cast(base* b)
52 {
53 return cast_of_base<T>(b);
54 }
55};
56
58{
59 template <class T>
60 static data::ref_ptr<const T, true> cast_const_of_base(const base* b);
61};
62
63template <class T>
65{
66 inline static data::ref_ptr<const T, true> cast_const(const base* b)
67 {
68 return cast_const_of_base<T>(b);
69 }
70};
71
75{
76protected:
78 friend class data::ref_ptr_impl<base,true>;
80 virtual ~base();
82 friend struct cast_helper_base;
84 template <class T>
86 {
87 return data::ref_ptr<T,true>(dynamic_cast<T*>(b));
88 }
89public:
91 virtual std::string get_type_name() const;
93 virtual std::string get_default_options() const;
95 std::string get_name_or_type_name() const;
97 virtual void on_register();
99 virtual void unregister();
101 virtual bool on_exit_request();
103 virtual void stream_stats(std::ostream&);
105 virtual data::ref_ptr<named, true> get_named();
107 virtual data::ref_ptr<node, true> get_node();
109 virtual data::ref_ptr<group, true> get_group();
111 virtual data::ref_ptr<const named, true> get_named_const() const;
113 virtual data::ref_ptr<const node, true> get_node_const() const;
115 virtual data::ref_ptr<const group, true> get_group_const() const;
117 template <class T>
122 template <class T>
127 template <class T>
129 return dynamic_cast<T*>(this);
130 }
132 template <class T>
133 const T* get_const_interface() const {
134 return dynamic_cast<const T*>(this);
135 }
137 virtual void update();
139 virtual void* get_user_data() const;
140
144
148 virtual bool self_reflect(cgv::reflect::reflection_handler&);
150
156 virtual std::string get_property_declarations();
158
161 virtual bool set_void(const std::string& property, const std::string& value_type, const void* value_ptr);
163 virtual void on_set(void* member_ptr);
165
168 virtual bool get_void(const std::string& property, const std::string& value_type, void* value_ptr);
170
173 virtual bool call_void(const std::string& method,
174 const std::vector<std::string>& param_value_types,
175 const std::vector<const void*>& param_value_ptrs,
176 const std::string& result_type = "",
177 void* result_value_ptr = 0);
178
180 void set(const std::string& property, const char* value) { const std::string& s(value); set_void(property, cgv::type::info::type_name<std::string>::get_name(), &s); }
182
185 template <typename T>
186 void set(const std::string& property, const T& value) { set_void(property, cgv::type::info::type_name<T>::get_name(), &value); }
188
191 template <typename T>
192 T get(const std::string& property) { T value; get_void(property, cgv::type::info::type_name<T>::get_name(), &value); return value; }
194
197 void multi_set(const std::string& property_assignments, bool report_error = true);
199
201 bool is_property(const std::string& property_name, std::string* type_name = 0);
203
206 void* find_member_ptr(const std::string& property_name, std::string* type_name = 0);
208};
209
210template <typename T>
211inline data::ref_ptr<T, true> cast_helper_base::cast_of_base(base* b)
212{
213 return base::cast_dynamic<T>(b);
214}
215
216template <typename T>
217inline data::ref_ptr<const T, true> cast_const_helper_base::cast_const_of_base(const base* b)
218{
219 return base::cast_dynamic<T>(b);
220}
221
222#if _MSC_VER > 1400
223CGV_TEMPLATE template class CGV_API cgv::data::ref_ptr<cgv::base::base>;
224CGV_TEMPLATE template class CGV_API std::vector<cgv::data::ref_ptr<cgv::base::base> >;
225#endif
226
227 }
228}
229
230
231#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
void set(const std::string &property, const char *value)
specialization of set method to support const char* as strings
Definition base.h:180
const T * get_const_interface() const
use dynamic type cast to check for the given interface
Definition base.h:133
T get(const std::string &property)
query a property of the element and perform standard conversions if necessary.
Definition base.h:192
data::ref_ptr< const T, true > cast_const()
const cast to arbitrary class, but use the casts to named, node and group from the interface
Definition base.h:123
T * get_interface()
use dynamic type cast to check for the given interface
Definition base.h:128
static data::ref_ptr< T, true > cast_dynamic(base *b)
use dynamic cast for upcast to given class
Definition base.h:85
data::ref_ptr< T, true > cast()
cast to arbitrary class, but use the casts to named, node and group from the interface
Definition base.h:118
void set(const std::string &property, const T &value)
set a property of the element to the given value and perform standard conversions if necessary.
Definition base.h:186
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
if you derive your class from this class, a ref_ptr will do reference counting in the inhereted ref_c...
Definition ref_counted.h:11
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
Definition base.h:37
data::ref_ptr< const base, true > const_base_ptr
ref counted pointer to const base
Definition base.h:40
cgv::data::ref_ptr< const type_interface, true > const_type_ptr
pointer to const type interface
Definition base.h:17
the cgv namespace
Definition print.h:11
Derive from this class to announce implementation of the method self_reflect.
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54