cgv
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 
10 namespace cgv {
11  namespace type {
12  namespace info {
13 
14 struct CGV_API type_interface;
15 
18 
19  }
20  }
21 }
22 #include <cgv/config/lib_end.h>
23 
24 #include "lib_begin.h"
25 
27 namespace cgv {
29  namespace base {
30 
31 class CGV_API base;
32 class CGV_API named;
33 class CGV_API node;
34 class CGV_API group;
35 
38 
39 struct cast_helper_base
40 {
41  template <class T>
42  static data::ref_ptr<T,true> cast_of_base(base* b);
43 };
44 
45 template <class T>
46 struct cast_helper : public cast_helper_base
47 {
48  inline static data::ref_ptr<T,true> cast(base* b)
49  {
50  return cast_of_base<T>(b);
51  }
52 };
53 
57 {
58 protected:
60  friend class data::ref_ptr_impl<base,true>;
62  virtual ~base();
64  friend struct cast_helper_base;
66  template <class T>
68  {
69  return data::ref_ptr<T,true>(dynamic_cast<T*>(b));
70  }
71 public:
73  virtual std::string get_type_name() const;
75  virtual std::string get_default_options() const;
77  virtual void on_register();
79  virtual void unregister();
81  virtual void stream_stats(std::ostream&);
83  virtual data::ref_ptr<named,true> get_named();
85  virtual data::ref_ptr<node,true> get_node();
87  virtual data::ref_ptr<group,true> get_group();
89  template <class T>
91  return cast_helper<T>::cast(this);
92  }
94  template <class T>
96  return dynamic_cast<T*>(this);
97  }
99  template <class T>
100  const T* get_const_interface() const {
101  return dynamic_cast<const T*>(this);
102  }
104  virtual void update();
106  virtual void* get_user_data() const;
107 
110 
115  virtual bool self_reflect(cgv::reflect::reflection_handler&);
117 
123  virtual std::string get_property_declarations();
125 
128  virtual bool set_void(const std::string& property, const std::string& value_type, const void* value_ptr);
130  virtual void on_set(void* member_ptr);
132 
135  virtual bool get_void(const std::string& property, const std::string& value_type, void* value_ptr);
137 
140  virtual bool call_void(const std::string& method,
141  const std::vector<std::string>& param_value_types,
142  const std::vector<const void*>& param_value_ptrs,
143  const std::string& result_type = "",
144  void* result_value_ptr = 0);
145 
147  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); }
149 
152  template <typename T>
153  void set(const std::string& property, const T& value) { set_void(property, cgv::type::info::type_name<T>::get_name(), &value); }
155 
158  template <typename T>
159  T get(const std::string& property) { T value; get_void(property, cgv::type::info::type_name<T>::get_name(), &value); return value; }
161 
164  void multi_set(const std::string& property_assignments, bool report_error = true);
166 
168  bool is_property(const std::string& property_name, std::string* type_name = 0);
170 
173  void* find_member_ptr(const std::string& property_name, std::string* type_name = 0);
175 };
176 
177 
178 template <typename T>
179 inline data::ref_ptr<T,true> cast_helper_base::cast_of_base(base* b)
180 {
181  return base::cast_dynamic<T>(b);
182 }
183 
184 #if _MSC_VER > 1400
185 CGV_TEMPLATE template class CGV_API cgv::data::ref_ptr<cgv::base::base>;
186 CGV_TEMPLATE template class CGV_API std::vector<cgv::data::ref_ptr<cgv::base::base> >;
187 #endif
188 
189  }
190 }
191 
192 
193 #include <cgv/config/lib_end.h>
cgv::base::base::get
T get(const std::string &property)
query a property of the element and perform standard conversions if necessary.
Definition: base.h:159
cgv::data::ref_ptr
Definition: ref_ptr.h:19
cgv::base::base_ptr
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
Definition: base.h:37
cgv::type::info::const_type_ptr
cgv::data::ref_ptr< const type_interface, true > const_type_ptr
pointer to const type interface
Definition: base.h:17
cgv::base::base::get_const_interface
const T * get_const_interface() const
use dynamic type cast to check for the given interface
Definition: base.h:100
cgv::base::base::set
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:153
cgv::reflect::reflection_handler
Definition: reflection_handler.h:63
cgv::data::ref_counted
Definition: ref_counted.h:11
cgv::base::base::cast_dynamic
static data::ref_ptr< T, true > cast_dynamic(base *b)
use dynamic cast for upcast to given class
Definition: base.h:67
cgv::reflect::self_reflection_tag
Derive from this class to announce implementation of the method self_reflect.
Definition: self_reflection_tag.h:12
cgv::base::base
Definition: base.h:57
cgv::base::base::get_interface
T * get_interface()
use dynamic type cast to check for the given interface
Definition: base.h:95
cgv::base::base::cast
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:90
cgv::base::base::set
void set(const std::string &property, const char *value)
specialization of set method to support const char* as strings
Definition: base.h:147
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::type::info::type_name
Definition: type_name.h:54