cgv
Loading...
Searching...
No Matches
get_reflection_handler.cxx
1#include "get_reflection_handler.h"
2#include <cgv/type/variant.h>
3#include <string.h>
4
5using namespace cgv::type;
6
7namespace cgv {
8 namespace reflect {
9
12 const std::string& _value_type,
13 void* _value_ptr,
14 abst_reflection_traits* _value_rt) : find_reflection_handler(_target), value_ptr(_value_ptr), value_type(_value_type), value_rt(_value_rt) {}
15
16get_reflection_handler::get_reflection_handler(const std::string& _target, void* _value_ptr, abst_reflection_traits* _value_rt)
17 : find_reflection_handler(_target), value_ptr(_value_ptr), value_rt(_value_rt) {}
18
20void get_reflection_handler::process_member_void(const std::string& member_name, void* member_ptr,
21 abst_reflection_traits* rt, GroupKind group_kind, unsigned grp_size)
22{
23 find_reflection_handler::process_member_void(member_name, member_ptr, rt, group_kind, grp_size);
24 valid = false;
25 if (value_rt) {
26 if (info::is_fundamental(value_rt->get_type_id())) {
27 if (info::is_fundamental(rt->get_type_id())) {
28 cgv::type::assign_variant(value_rt->get_type_name(), value_ptr, rt->get_type_name(), member_ptr);
29 valid = true;
30 }
31 else if (info::is_fundamental(rt->get_type_id())) {
32 std::string tmp_str;
33 get_variant(tmp_str, rt->get_type_name(), member_ptr);
34 value_rt->set_from_string(value_ptr, tmp_str);
35 valid = true;
36 }
37 }
38 if (!valid && rt->has_string_conversions() && value_rt->has_string_conversions()) {
39 std::string tmp;
40 rt->get_to_string(member_ptr, tmp);
41 valid = value_rt->set_from_string(value_ptr, tmp);
42 }
43 if (!valid && rt->has_string_conversions() && value_rt->get_type_id() == info::TI_STRING) {
44 rt->get_to_string(member_ptr, *static_cast<std::string*>(value_ptr));
45 valid = true;
46 }
47 }
48 else {
49 if (info::is_fundamental(rt->get_type_id())) {
50 cgv::type::assign_variant(value_type, value_ptr, rt->get_type_name(), member_ptr);
51 valid = true;
52 }
53 else if (value_type == rt->get_type_name()) {
54 memcpy(value_ptr, member_ptr, rt->size());
55 valid = true;
56 }
58 rt->get_to_string(member_ptr, *static_cast<std::string*>(value_ptr));
59 valid = true;
60 }
61 }
62}
63
64 }
65}
The cgv::reflect::find_reflection_hander steers traversal to a specific member and calls the virtual ...
virtual void process_member_void(const std::string &member_name, void *member_ptr, abst_reflection_traits *rt, GroupKind group_kind=GK_NO_GROUP, unsigned grp_size=-1)
virtual method that is overloaded by derived classes to handle the target member
get_reflection_handler(const std::string &_target, const std::string &_value_type, void *_value_ptr, abst_reflection_traits *_value_rt=0)
construct from target, value type and pointer to value
void process_member_void(const std::string &member_name, void *member_ptr, abst_reflection_traits *rt, GroupKind group_kind, unsigned grp_size)
copy value of member to external value pointer
GroupKind
different support group types
@ TI_STRING
wide character type
Definition type_id.h:31
namespace for compile time type information
the cgv namespace
Definition print.h:11
abstract interface for type reflection with basic type management and optional string conversion
virtual unsigned size() const =0
return the size of the type
virtual bool has_string_conversions() const
whether type can be converted to string, defaults to false
virtual cgv::type::info::TypeId get_type_id() const =0
return the type id
virtual const char * get_type_name() const =0
return the type name
virtual void get_to_string(const void *instance_ptr, std::string &str_val)
convert given instance into a string value
virtual bool set_from_string(void *instance_ptr, const std::string &str_val)
convert a given string value to the reflected type and store in the instance pointer
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54