cgv
cgv::reflect::get_reflection_handler Class Reference

#include <get_reflection_handler.h>

Inheritance diagram for cgv::reflect::get_reflection_handler:
cgv::reflect::find_reflection_handler cgv::reflect::reflection_handler

Public Types

enum  GroupTraversal
 different values for group traversal strategy More...
 
enum  GroupKind
 different support group types
 

Public Member Functions

 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
 
 get_reflection_handler (const std::string &_target, void *_value_ptr, abst_reflection_traits *_value_rt)
 construct from target, pointer to value and reflection_traits
 
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
 
bool found_target () const
 return whether target has been found
 
bool found_valid_target () const
 return whether a valid target has been found. The semantic of being valid is defined in derived classes.
 
void * get_member_ptr () const
 in case a valid target has been found, return a pointer to the member
 
const std::string & get_member_name () const
 in case a valid target has been found, return the name of the member
 
abst_reflection_traitsget_reflection_traits () const
 in case a valid target has been found, return a point to the reflection traits describing the type of the member
 
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
 
int reflect_group_begin (GroupKind group_kind, const std::string &group_name, void *group_ptr, abst_reflection_traits *rt, unsigned grp_size)
 overload to navigate grouped reflection information
 
void reflect_group_end (GroupKind group_kind)
 ensure that matched group pointers are found also in case that groups are traversed further and no group member corresponds to target pointer
 
bool reflect_member_void (const std::string &member_name, void *member_ptr, abst_reflection_traits *rt)
 check for target during member reflection
 
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)
 ignore methods
 

Static Public Member Functions

static std::string group_traversal_name (GroupTraversal gt)
 return the group traversals as a string
 
static const char * group_kind_name (GroupKind gk)
 return the group kind as a string
 
static bool is_array_kind (GroupKind gk)
 check whether a group kind is of array or vector kind
 

interface used by reflect and self_reflect functions

virtual bool is_creative () const
 give information on whether reflection_handler creates object (defaults to false) More...
 
template<typename T >
bool reflect_member (const std::string &member_name, T &member_ref, bool hard_cast=false)
 
template<typename T , unsigned n>
bool reflect_member (const std::string &member_name, T(&member_ref)[n])
 reflect a member of constant size array type
 
template<typename T >
bool reflect_member (const std::string &member_name, std::vector< T > &member_ref)
 reflect a member of vector type
 
template<typename T >
bool reflect_member (const std::string &member_name, T *&member_ref)
 reflect a member of pointer type. More...
 
template<typename M >
bool reflect_method (const std::string &method_name, M m)
 
template<typename B >
bool reflect_base (B &base_ref)
 reflect a base class with its members
 
template<typename T , typename S >
bool reflect_array (const std::string &member_name, T *&member_ref, S &size)
 reflect a dynamic array member of vector type
 

Detailed Description

provides access to a member variable of an instance. Use the cgv::reflect::get_member() function for simplest usage of this class.

Member Enumeration Documentation

◆ GroupTraversal

different values for group traversal strategy

@ basic types with helper functions

Member Function Documentation

◆ is_creative()

bool cgv::reflect::reflection_handler::is_creative ( ) const
virtualinherited

give information on whether reflection_handler creates object (defaults to false)

give information on whether reflection_handler creates object

Reimplemented in cgv::data::ascii_read_reflection_handler, and cgv::data::binary_read_reflection_handler.

◆ reflect_group_begin()

int cgv::reflect::reflection_handler::reflect_group_begin ( GroupKind  group_kind,
const std::string &  group_name,
void *  group_ptr,
abst_reflection_traits rt,
unsigned  grp_size = -1 
)
protectedvirtualinherited

abstract interface to start reflection of a group of members.

The return value gives information about further traversal of the group:

  • GT_TERMINATE ... terminate traversal completely
    • GT_SKIP ... skip traversal of group
  • GT_COMPLETE ... traverse group completely
    • index i >= 0 ... traverse only the i-th member of the group. Depending on the group kind, the remaining parameters are given as follows:
    • GK_BASE_CLASS ... group_name and grp_size are undefined, group_ptr is pointer to instance of base class, rt reflects base class
    • GK_STRUCTURE ... group_name is instance name, group_ptr is pointer to instance, rt reflects type of structure, grp_size is undefined,
    • GK_VECTOR ... group_name is vector name, group_ptr is pointer to vector data structure, rt reflects element type, grp_size is size of vector
    • GK_ARRAY ... group_name is array name, group_ptr is pointer to first array element, rt reflects element type, grp_size is size of array.
    • GK_POINTER ... group_name is pointer name, group_ptr is pointer to first array element, rt reflects type to which pointer poits, grp_size is undefined.

Reimplemented in cgv::data::ascii_write_reflection_handler, cgv::data::ascii_read_reflection_handler, cgv::data::ascii_reflection_handler, and cgv::reflect::debug_reflection_handler.

◆ reflect_group_end()

void cgv::reflect::reflection_handler::reflect_group_end ( GroupKind  group_kind)
protectedvirtualinherited

abstract interface to terminate reflection of a group of members

This function should only be called if group is traversed completely.

Reimplemented in cgv::data::ascii_reflection_handler, and cgv::reflect::debug_reflection_handler.

◆ reflect_member() [1/2]

template<typename T >
bool cgv::reflect::reflection_handler::reflect_member ( const std::string &  member_name,
T &  member_ref,
bool  hard_cast = false 
)
inherited

call this to reflect a member by member name and reference to the member. The member type is deduced from the reference via templates. The method uses reflect_member_impl to dispath types with implementation of a self_reflect method and types without. For polymorphic objects with a polymorphic self_reflect() method the parameter hard_cast steers whether the concrete implementation T::self_reflect() is used or the overloaded function member_ref.self_reflect(). This is important for self reflection of base classes in polymorphic objects where hard_cast is set to true. In most other cases one can use the default argument false.

◆ reflect_member() [2/2]

template<typename T >
bool cgv::reflect::reflection_handler::reflect_member ( const std::string &  member_name,
T *&  member_ref 
)
inherited

reflect a member of pointer type.

This is only a minimal implementation that allows pointers to memory allocated with new. No reference counting or pointers into memory ranges allocated differently are supported. This will be later on.

◆ reflect_method()

template<typename M >
bool cgv::reflect::reflection_handler::reflect_method ( const std::string &  method_name,
m 
)
inherited

call this to reflect a method by method name and reference to the member. The method type is deduced from the reference via templates. This only works, if you additionally include the header <cgv/reflect/method_interface_impl.h>, where the template code is located. This header is not included automatically, because of its length.

To give names to the parameters, append them to the name enclosed in parenthesis, i.e. "sin(x)" or "dot_prod(p,q)".


The documentation for this class was generated from the following files: