cgv
Loading...
Searching...
No Matches
cgv::reflect::reflection_handler Class Referenceabstract

the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base. More...

#include <reflection_handler.h>

Inheritance diagram for cgv::reflect::reflection_handler:
cgv::base::call_reflection_handler cgv::base::property_declaration_reflection_handler cgv::data::io_reflection_handler cgv::reflect::debug_reflection_handler cgv::reflect::find_reflection_handler cgv::data::ascii_reflection_handler cgv::data::binary_reflection_handler cgv::reflect::get_reflection_handler cgv::reflect::set_reflection_handler cgv::data::ascii_read_reflection_handler cgv::data::ascii_write_reflection_handler cgv::data::binary_read_reflection_handler cgv::data::binary_write_reflection_handler

Classes

struct  nesting_info
 for each nesting during traversal a nesting info is pushed back to the end of the nesting info stack More...
 

Public Types

enum  GroupTraversal { GT_TERMINATE = -3 , GT_SKIP = -2 , GT_COMPLETE = -1 }
 @ basic types with helper functions More...
 
enum  GroupKind {
  GK_NO_GROUP , GK_BASE_CLASS , GK_STRUCTURE , GK_VECTOR ,
  GK_ARRAY , GK_POINTER
}
 different support group types More...
 

Public Member Functions

interface used by reflect and self_reflect functions
virtual bool is_creative () const
 give information on whether reflection_handler creates object (defaults to false)
 
template<typename T >
bool reflect_member (const std::string &member_name, T &member_ref, bool hard_cast=false)
 call this to reflect a member by member name and reference to the member.
 
template<typename M >
bool reflect_method (const std::string &method_name, M m)
 call this to reflect a method by method name and reference to the member.
 
template<typename B >
bool reflect_base (B &base_ref)
 reflect a base class with its members
 
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.
 
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
 

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
 

Protected Member Functions

internal helper functions
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
 
bool group_end (GroupKind gk)
 updates the nesting info at the end of group and always returns true
 
template<typename T , typename RT , typename D >
bool self_reflect_member (const std::string &member_name, T &member_ref, const RT &, const D &, bool hard_cast)
 implementation of reflection with internal or external self_reflect function
 
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
 

Protected Attributes

management of nesting information
std::vector< nesting_infonesting_info_stack
 stack of nesting_info used during the reflection process
 

Friends

struct detail
 
template<typename T >
bool reflect_enum (reflection_handler &rh, const std::string &name, T &instance, const std::string &declarations)
 
template<typename T >
bool reflect_string (reflection_handler &rh, const std::string &name, T &instance)
 

interface to be implemented by derived reflection handlers

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.
 
virtual void reflect_group_end (GroupKind group_kind)
 abstract interface to terminate reflection of a group of members
 
virtual bool reflect_member_void (const std::string &member_name, void *member_ptr, abst_reflection_traits *rt)=0
 abstract interface to reflect a member variable, where the member type is specified as a string.
 
virtual 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)=0
 abstract interface to reflect a method, where return and parameter types are specified as strings.
 
virtual ~reflection_handler ()
 declare virtual destructor
 

Detailed Description

the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.

It is used to process type information by describing member variables and function (methods) to the handler with its templated methods reflect_member() and reflect_method() or the non templated versions with the suffix _void.

Definition at line 62 of file reflection_handler.h.

Member Enumeration Documentation

◆ GroupKind

different support group types

Definition at line 85 of file reflection_handler.h.

◆ GroupTraversal

@ basic types with helper functions

different values for group traversal strategy

Definition at line 81 of file reflection_handler.h.

Constructor & Destructor Documentation

◆ ~reflection_handler()

cgv::reflect::reflection_handler::~reflection_handler ( )
virtual

declare virtual destructor

Definition at line 14 of file reflection_handler.cxx.

Member Function Documentation

◆ group_end()

bool cgv::reflect::reflection_handler::group_end ( GroupKind  gk)
protected

updates the nesting info at the end of group and always returns true

Definition at line 75 of file reflection_handler.cxx.

References nesting_info_stack, and reflect_group_end().

Referenced by reflect_array(), and reflect_member().

◆ group_kind_name()

const char * cgv::reflect::reflection_handler::group_kind_name ( GroupKind  gk)
static

◆ group_traversal_name()

std::string cgv::reflect::reflection_handler::group_traversal_name ( GroupTraversal  gt)
static

return the group traversals as a string

Definition at line 45 of file reflection_handler.cxx.

References cgv::utils::to_string().

Referenced by process_structural_group_begin(), and reflect_member().

◆ is_array_kind()

bool cgv::reflect::reflection_handler::is_array_kind ( GroupKind  gk)
static

check whether a group kind is of array or vector kind

Definition at line 26 of file reflection_handler.cxx.

◆ is_creative()

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

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, cgv::data::binary_read_reflection_handler, and cgv::reflect::set_reflection_handler.

Definition at line 19 of file reflection_handler.cxx.

◆ process_structural_group_begin()

reflection_handler::GroupTraversal cgv::reflect::reflection_handler::process_structural_group_begin ( GroupKind  gk,
const std::string &  member_name,
GroupTraversal  gt 
)
protected

type independent part of the reflect_group method that starts the group traversal

Definition at line 61 of file reflection_handler.cxx.

References group_kind_name(), group_traversal_name(), and nesting_info_stack.

◆ reflect_array()

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

reflect a dynamic array member of vector type

Definition at line 476 of file reflection_handler.h.

References group_end(), nesting_info_stack, reflect_array_begin(), and reflect_member().

◆ reflect_array_begin()

int cgv::reflect::reflection_handler::reflect_array_begin ( GroupKind  group_kind,
const std::string &  group_name,
void *  group_ptr,
abst_reflection_traits rt,
unsigned  grp_size 
)
protected

type independent functionality of array reflection

Definition at line 82 of file reflection_handler.cxx.

References group_kind_name(), nesting_info_stack, and reflect_group_begin().

Referenced by reflect_array().

◆ reflect_base()

template<typename B >
bool cgv::reflect::reflection_handler::reflect_base ( B &  base_ref)

reflect a base class with its members

Definition at line 357 of file reflection_handler.h.

◆ 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 
)
protectedvirtual

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::base::property_declaration_reflection_handler, cgv::reflect::debug_reflection_handler, cgv::reflect::find_reflection_handler, cgv::data::ascii_reflection_handler, cgv::data::ascii_read_reflection_handler, and cgv::data::ascii_write_reflection_handler.

Definition at line 31 of file reflection_handler.cxx.

Referenced by reflect_array_begin(), and reflect_member().

◆ reflect_group_end()

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

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, cgv::reflect::debug_reflection_handler, and cgv::reflect::find_reflection_handler.

Definition at line 40 of file reflection_handler.cxx.

Referenced by group_end().

◆ reflect_member() [1/4]

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

reflect a member of vector type

Definition at line 433 of file reflection_handler.h.

◆ reflect_member() [2/4]

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

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.

Definition at line 323 of file reflection_handler.h.

Referenced by reflect_array(), reflect_member(), cgv::app::navigator::self_reflect(), cgv::gui::base_provider::self_reflect(), cgv::gui::base_provider_generator::self_reflect(), cgv::gui::key_control< T >::self_reflect(), cgv::render::shader_config::self_reflect(), vr_view_interactor::self_reflect(), and vr_emulator::self_reflect().

◆ reflect_member() [3/4]

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

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.

Definition at line 443 of file reflection_handler.h.

References group_end(), group_traversal_name(), nesting_info_stack, reflect_group_begin(), and reflect_member().

◆ reflect_member() [4/4]

template<typename T , unsigned n>
bool cgv::reflect::reflection_handler::reflect_member ( const std::string &  member_name,
T(&)  member_ref[n] 
)

reflect a member of constant size array type

Definition at line 395 of file reflection_handler.h.

◆ reflect_member_void()

virtual bool cgv::reflect::reflection_handler::reflect_member_void ( const std::string &  member_name,
void *  member_ptr,
abst_reflection_traits rt 
)
protectedpure virtual

◆ reflect_method()

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

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)".

Definition at line 333 of file reflection_handler.h.

◆ reflect_method_void()

virtual bool cgv::reflect::reflection_handler::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 
)
protectedpure virtual

abstract interface to reflect a method, where return and parameter types are specified as strings.

Returns whether to continue the reflection.

Implemented in cgv::data::io_reflection_handler, cgv::base::property_declaration_reflection_handler, cgv::base::call_reflection_handler, cgv::reflect::debug_reflection_handler, and cgv::reflect::find_reflection_handler.

◆ self_reflect_member()

template<typename T , typename RT , typename D >
bool cgv::reflect::reflection_handler::self_reflect_member ( const std::string &  member_name,
T &  member_ref,
const RT &  ,
const D &  ,
bool  hard_cast 
)
inlineprotected

implementation of reflection with internal or external self_reflect function

Definition at line 100 of file reflection_handler.h.

Friends And Related Symbol Documentation

◆ detail

friend struct detail
friend

Definition at line 77 of file reflection_handler.h.

Member Data Documentation

◆ nesting_info_stack

std::vector<nesting_info> cgv::reflect::reflection_handler::nesting_info_stack
protected

stack of nesting_info used during the reflection process

Definition at line 134 of file reflection_handler.h.

Referenced by group_end(), process_structural_group_begin(), reflect_array(), reflect_array_begin(), and reflect_member().


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