cgv
Loading...
Searching...
No Matches
debug_reflection_handler.cxx
1#include "debug_reflection_handler.h"
2#include <cgv/utils/scan.h>
3
4using namespace cgv::type;
5
6namespace cgv {
7 namespace reflect {
8
9std::string debug_reflection_handler::extend_name(const std::string& name) const
10{
11 std::string res;
12 for (unsigned i=0; i<nesting_info_stack.size(); ++i) {
13 res += *nesting_info_stack[i].name;
14 switch (nesting_info_stack[i].group_kind) {
15 case GK_BASE_CLASS :
16 case GK_STRUCTURE :
17 res += ".";
18 break;
19 case GK_VECTOR :
20 case GK_ARRAY :
21 res += "[";
22 res += cgv::utils::to_string(nesting_info_stack[i].idx) + "]";
23 break;
24 case GK_POINTER :
25 res += "->";
26 break;
27 }
28 }
29 res += name;
30 return res;
31}
32
33int debug_reflection_handler::reflect_group_begin(GroupKind group_kind, const std::string& group_name, void* group_ptr, abst_reflection_traits* rt, unsigned grp_size)
34{
35 output += tab;
36 if (group_kind != GK_BASE_CLASS) {
37 output += extend_name(group_name);
38 output += ":";
39 }
40 output += group_kind_name(group_kind);
41 switch (group_kind) {
42 case GK_VECTOR :
43 case GK_ARRAY :
44 output += "[";
45 output += cgv::utils::to_string(grp_size);
46 output += "]";
47 break;
48 case GK_STRUCTURE :
49 case GK_BASE_CLASS :
50 output += "(";
51 output += rt->get_type_name();
52 output += ")";
53 if (rt->has_string_conversions()) {
54 output += "~'";
55 std::string delta;
56 rt->get_to_string(group_ptr, delta);
57 output += delta;
58 output += "'";
59 }
60 }
61 output += "\n";
62 tab += " ";
63 return GT_COMPLETE;
64}
65
68{
69 if (tab.size() > 1)
70 tab = tab.substr(0, tab.size()-2);
71}
72
73bool debug_reflection_handler::reflect_member_void(const std::string& member_name, void* member_ptr, abst_reflection_traits* rt)
74{
75 output += tab;
76 output += extend_name(member_name);
77 output += ":";
78 output += rt->get_type_name();
79 if (rt->get_type_id() == info::TI_STRING) {
80 output += '=';
81 output += '"';
82 output += cgv::utils::escape_special(*((const std::string*)member_ptr));
83 output += '"';
84 }
85 else if (rt->has_string_conversions()) {
86 std::string delta;
87 rt->get_to_string(member_ptr, delta);
88 output += "=";
89 output += delta;
90 }
91 output += "\n";
92 return true;
93}
94
95bool debug_reflection_handler::reflect_method_void(const std::string& method_name, method_interface* mi_ptr,
96 abst_reflection_traits* return_traits, const std::vector<abst_reflection_traits*>& param_value_traits)
97{
98 output += method_name;
99 output += ":";
100 output += return_traits->get_type_name();
101 output += "(";
102 for (unsigned i=0; i<param_value_traits.size(); ++i) {
103 output += param_value_traits[i]->get_type_name();
104 if (i+1 < param_value_traits.size())
105 output += ",";
106 }
107 output += ")\n";
108 return true;
109}
110 }
111}
bool reflect_method_void(const std::string &method_name, method_interface *mi_ptr, abst_reflection_traits *return_traits, const std::vector< abst_reflection_traits * > &param_value_traits)
empty implementation
std::string output
contains the description in form of a string
void reflect_group_end(GroupKind group_kind)
abstract interface to start reflection of a group of members
int reflect_group_begin(GroupKind group_kind, const std::string &group_name, void *group_ptr, abst_reflection_traits *rt, unsigned grp_size)
abstract interface to start reflection of a group of members.
bool reflect_member_void(const std::string &member_name, void *member_ptr, abst_reflection_traits *rt)
abstract interface to reflect a member variable, where the member type is specified as a string.
std::vector< nesting_info > nesting_info_stack
stack of nesting_info used during the reflection process
GroupKind
different support group types
static const char * group_kind_name(GroupKind gk)
return the group kind as a string
@ TI_STRING
wide character type
Definition type_id.h:31
namespace for compile time type information
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
std::string escape_special(const std::string &s)
escapes the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?
Definition scan.cxx:205
the cgv namespace
Definition print.h:11
Helper functions to process strings.
abstract interface for type reflection with basic type management and optional string conversion
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
abstract interface to call a method of a given instance.