rttr::visitor Class Reference

The class visitor, is used for visiting your registered accessors of a type at compile time. More...

#include <visitor.h>

Classes

struct  constructor_function_info
 The constructor_function_info class is used to forward all information during registration of a constructor function. More...
 
struct  constructor_info
 The constructor_info class is used to forward all information during registration of a constructor. More...
 
struct  method_info
 The method_info class is used to forward all information during registration of a method. More...
 
struct  property_getter_setter_info
 The method_info class is used to forward all information during registration of a property. More...
 
struct  property_info
 The property_info class is used to forward all information during registration of a property. More...
 
struct  type_info
 The type_info class is used to forward all information during registration of a class. More...
 

Public Member Functions

 visitor ()
 The constructor of the visitor class. More...
 
virtual ~visitor ()
 The destructor of the visitor class. More...
 
void visit (type t)
 Calling this function will indirectly call the visit functions for all registered types members (constructors, methods, properties, etc...) This includes also registered base classes. More...
 
void visit (method meth)
 Calling this function will indirectly call the function visit_method() for the underlying registered type. More...
 
void visit (constructor ctor)
 Calling this function will indirectly call the function visit_constructor() or visit_constructor_function() for the underlying registered type. More...
 
void visit (property prop)
 Calling this function will indirectly call one of the functions: More...
 
template<typename T , typename... Ctor_Args>
void visit_constructor (const constructor_info< T > &info)
 This function will be called when you visit a constructor via: visit(type) or directlyvisit(constructor). More...
 
template<typename T >
void visit_constructor_function (const constructor_function_info< T > &info)
 This function will be called when you visit a constructor function via: visit(type) or visit(constructor). More...
 
template<typename T >
void visit_getter_setter_property (const property_getter_setter_info< T > &info)
 This function will be called when you visit a property via: visit(property). More...
 
template<typename T >
void visit_global_getter_setter_property (const property_getter_setter_info< T > &info)
 This function will be called when you visit a global property via: visit(property). More...
 
template<typename T >
void visit_global_method (const method_info< T > &info)
 This function will be called when you visit a global method via: visit(method). More...
 
template<typename T >
void visit_global_property (const property_info< T > &info)
 This function will be called when you visit a global property via: visit(property). More...
 
template<typename T >
void visit_global_readonly_property (const property_info< T > &info)
 This function will be called when you visit a global read only property via: visit(property). More...
 
template<typename T >
void visit_method (const method_info< T > &info)
 This function will be called when you visit a type method via: visit(type) or visit(method). More...
 
template<typename T >
void visit_property (const property_info< T > &info)
 This function will be called when you visit a property via: visit(property). More...
 
template<typename T >
void visit_readonly_property (const property_info< T > &info)
 This function will be called when you visit a read only property via: visit(property). More...
 
template<typename T , typename... Base_Classes>
void visit_type_begin (const type_info< T > &info)
 This function will be called when you visit a type via: visit(type) It is the first function that will be invoked, when visiting a type. More...
 
template<typename T , typename... Base_Classes>
void visit_type_end (const type_info< T > &info)
 This function will be called when you visit a type via: visit(type). More...
 

Detailed Description

The class visitor, is used for visiting your registered accessors of a type at compile time.

Sometimes it might be necessary to get access to the underlying registered accessor (e.g. function pointers, object pointers, etc...) of a type. For example in order to bind a type to a scripting library, which only allows to register concrete types. The generic approach of using a visitor will solve this problem. Furthermore, because it is template based, you can write one visitor to iterate over all your types in a generic way and have access to the static type information.

Own visitor

In order to implement your own visitor class, you have to derive from the class visitor and reimplement the following visitor function templates:

  1. void visitor::visit_type_begin(const type_info<T>& info)
  2. void visitor::visit_type_end(const type_info<T>& info);
  3. void visitor::visit_constructor(const constructor_info<T>& info);
  4. void visitor::visit_constructor_function(const constructor_function_info<T>& info);
  5. void visitor::visit_method(const method_info<T>& info);
  6. void visitor::visit_global_method(const method_info<T>& info);

and add the macro RTTR_ENABLE(visitor); in the class body.

Using a visitor

#include "print_visitor.h" // IMPORTANT: You have to include your visitor always before the include of the `<rttr/registration>`
#include <rttr/registration>
{
.method("meow", &cat::meow);
}
int main()
{
print_visitor vi;
type t = type:get_by_name("cat");
vi.visit(t);
}

It is very important that the include of the visitor is done before the include of <rttr/registration>, otherwise the visitor will not be found by rttr. The reason for that is, the visit functions will be created at compile time, so the declaration has to be before the instantiation. Because of limitations of the c++ preprocessor, it is not possible to include the visitor or the <rttr/registration> header in a precompiled header and use the visitor functionality. All custom visitors will not be found.

Constructor & Destructor Documentation

rttr::visitor::visitor ( )

The constructor of the visitor class.

virtual rttr::visitor::~visitor ( )
virtual

The destructor of the visitor class.

Member Function Documentation

void rttr::visitor::visit ( type  t)

Calling this function will indirectly call the visit functions for all registered types members (constructors, methods, properties, etc...) This includes also registered base classes.

void rttr::visitor::visit ( method  meth)

Calling this function will indirectly call the function visit_method() for the underlying registered type.

void rttr::visitor::visit ( constructor  ctor)

Calling this function will indirectly call the function visit_constructor() or visit_constructor_function() for the underlying registered type.

void rttr::visitor::visit ( property  prop)

Calling this function will indirectly call one of the functions:

template<typename T , typename... Ctor_Args>
void rttr::visitor::visit_constructor ( const constructor_info< T > &  info)

This function will be called when you visit a constructor via: visit(type) or directlyvisit(constructor).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
Ctor_ArgsThe argument of the constructor
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(constructor)
template<typename T >
void rttr::visitor::visit_constructor_function ( const constructor_function_info< T > &  info)

This function will be called when you visit a constructor function via: visit(type) or visit(constructor).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(constructor)
template<typename T >
void rttr::visitor::visit_getter_setter_property ( const property_getter_setter_info< T > &  info)

This function will be called when you visit a property via: visit(property).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(property), type::get_property()
template<typename T >
void rttr::visitor::visit_global_getter_setter_property ( const property_getter_setter_info< T > &  info)

This function will be called when you visit a global property via: visit(property).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(property), type::get_global_property()
template<typename T >
void rttr::visitor::visit_global_method ( const method_info< T > &  info)

This function will be called when you visit a global method via: visit(method).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(method), type::get_global_method()
template<typename T >
void rttr::visitor::visit_global_property ( const property_info< T > &  info)

This function will be called when you visit a global property via: visit(property).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(property), type::get_global_property()
template<typename T >
void rttr::visitor::visit_global_readonly_property ( const property_info< T > &  info)

This function will be called when you visit a global read only property via: visit(property).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(property), type::get_global_property()
template<typename T >
void rttr::visitor::visit_method ( const method_info< T > &  info)

This function will be called when you visit a type method via: visit(type) or visit(method).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(method), type::get_method()
template<typename T >
void rttr::visitor::visit_property ( const property_info< T > &  info)

This function will be called when you visit a property via: visit(property).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(property), type::get_property()
template<typename T >
void rttr::visitor::visit_readonly_property ( const property_info< T > &  info)

This function will be called when you visit a read only property via: visit(property).

Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
infoThis object will be provided by RTTR, use it's public members and the using's

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
visit(property), type::get_property()
template<typename T , typename... Base_Classes>
void rttr::visitor::visit_type_begin ( const type_info< T > &  info)

This function will be called when you visit a type via: visit(type) It is the first function that will be invoked, when visiting a type.

When the visiting type has base classes, it will be first invoked with he most basic type and last step with the current type. Reimplement this function, when you need the static compile time type information.

Parameters
TInternal template type, do not work with this parameter directly.
Base_Classes...A list of base classes, ascending order
infoThis object will be provided by RTTR, use it's public members and the using's
Remarks
You have to register your type via: registration::class_ otherwise the static type information for invoke cannot be retrieved. The signature has to match exactly the declaration here, otherwise it will not be invoked.

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
type::get_base_classes()
template<typename T , typename... Base_Classes>
void rttr::visitor::visit_type_end ( const type_info< T > &  info)

This function will be called when you visit a type via: visit(type).

It is the last function that will be invoked, when visiting a type. When the visiting type has base classes, it will be first invoked with he most basic type and last step with the current type. Reimplement this function, when you need the static compile time type information.

Parameters
TInternal type type, do not work with this parameter directly.
Base_Classes...A list of base classes, ascending order
infoThis object will be provided by RTTR, use it's public members and the using's
Remarks
You have to register your type via: registration::class_ otherwise the static type information for invoke cannot be retrieved. The signature has to match exactly the declaration here, otherwise it will not be invoked.

You normally don't call this function directly. However, make sure this function is declared public, otherwise it cannot be invoked.

See also
type::get_base_classes()

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