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 }
57 else if (value_type == cgv::type::info::type_name<std::string>::get_name() && rt->has_string_conversions()) {
58 rt->get_to_string(member_ptr, *static_cast<std::string*>(value_ptr));
59 valid = true;
60 }
61 }
62}
63
64 }
65}
find_reflection_handler(const std::string &_target)
construct from textual target description
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
in this namespace reflection of types is implemented
@ TI_STRING
wide character type
Definition type_id.h:31
namespace for compile time type information
Definition bool32_t.h:7
this header is dependency free
Definition print.h:11
abstract interface for type reflection with basic type management and optional string conversion
static const char * get_name()
return special name for standard types or type name from RTTI cleaned from keywords for all other typ...
Definition type_name.h:56