cgv
Loading...
Searching...
No Matches
reflection_handler.cxx
1#include "reflection_handler.h"
2
3#include <vector>
4#include <cgv/type/info/type_name.h>
5#include <cgv/utils/convert.h>
7#include <cgv/type/traits/method_pointer.h>
8#include <cgv/type/info/type_id.h>
9
10namespace cgv {
11 namespace reflect {
12
17
20{
21 return false;
22}
23
24
27{
28 return gk == GK_VECTOR || gk == GK_ARRAY;
29}
30
32 const std::string& group_name,
33 void* group_ptr,
35 unsigned grp_size)
36{
37 return GT_COMPLETE;
38}
39
43
46{
47 switch (gt) {
48 case GT_TERMINATE : return "terminate";
49 case GT_SKIP : return "skip";
50 case GT_COMPLETE : return "complete";
51 default: return cgv::utils::to_string((int&)gt)+"-th element";
52 }
53}
54
56{
57 static const char* names[] = { "no group", "base class", "struct", "vector", "array", "pointer" };
58 return names[gk];
59}
60
62{
63 switch (gt) {
64 case GT_COMPLETE :
65 nesting_info_stack.push_back(nesting_info(gk, &member_name));
66 case GT_TERMINATE :
67 case GT_SKIP :
68 return gt;
69 default:
70 std::cerr << "group traversal " << group_traversal_name(gt) << " not allowed for " << member_name << " on group of kind '" << group_kind_name(gk) << "'!" << std::endl;
71 return GT_TERMINATE;
72 }
73}
74
76{
77 nesting_info_stack.pop_back();
79 return true;
80}
81
82int reflection_handler::reflect_array_begin(GroupKind group_kind, const std::string& group_name, void* group_ptr, abst_reflection_traits* rt, unsigned grp_size)
83{
84 int grp_tra = reflect_group_begin(group_kind, group_name, group_ptr, rt, grp_size);
85 if (grp_tra == GT_TERMINATE || grp_tra == GT_SKIP)
86 return grp_tra;
87
88 if (grp_tra == GT_COMPLETE)
89 nesting_info_stack.push_back(nesting_info(group_kind, &group_name));
90 else {
91 if (grp_tra >= 0 && grp_tra < (int)grp_size)
92 nesting_info_stack.push_back(nesting_info(group_kind, &group_name, grp_tra));
93 else {
94 std::cerr << "invalid access to " << group_kind_name(group_kind) << " " << group_name << ": index "
95 << grp_tra << " out of range [0," << grp_size << "[" << std::endl;
96 return GT_TERMINATE;
97 }
98 }
99 return grp_tra;
100}
101
102 }
103}
int reflect_array_begin(GroupKind group_kind, const std::string &group_name, void *group_ptr, abst_reflection_traits *rt, unsigned grp_size)
type independent functionality of array reflection
virtual bool is_creative() const
give information on whether reflection_handler creates object (defaults to false)
virtual void reflect_group_end(GroupKind group_kind)
abstract interface to terminate reflection of a group of members
static std::string group_traversal_name(GroupTraversal gt)
return the group traversals as a string
GroupTraversal process_structural_group_begin(GroupKind gk, const std::string &member_name, GroupTraversal gt)
type independent part of the reflect_group method that starts the group traversal
virtual ~reflection_handler()
declare virtual destructor
virtual int reflect_group_begin(GroupKind group_kind, const std::string &group_name, void *group_ptr, abst_reflection_traits *rt, unsigned grp_size=-1)
abstract interface to start reflection of a group of members.
std::vector< nesting_info > nesting_info_stack
stack of nesting_info used during the reflection process
GroupKind
different support group types
static bool is_array_kind(GroupKind gk)
check whether a group kind is of array or vector kind
static const char * group_kind_name(GroupKind gk)
return the group kind as a string
GroupTraversal
@ basic types with helper functions
bool group_end(GroupKind gk)
updates the nesting info at the end of group and always returns true
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
the cgv namespace
Definition print.h:11
Helper functions to process enum declarations from strings.
abstract interface for type reflection with basic type management and optional string conversion
for each nesting during traversal a nesting info is pushed back to the end of the nesting info stack