rttr  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Public Member Functions | List of all members
rttr::constructor Class Reference

The constructor class provides several meta information about a constructor and can be invoked. More...

#include <constructor.h>

Public Member Functions

type get_declaring_type () const
 Returns the type of the class or struct that declares this constructor. More...
 
type get_instanciated_type () const
 Returns the type object of the instantiated type. More...
 
variant get_metadata (int key) const
 Returns the metadata for the given key key. More...
 
variant get_metadata (const std::string &key) const
 Returns the metadata for the given key key. More...
 
std::vector< typeget_parameter_types () const
 Returns a list of type objects representing the number, order and type of the parameters for this constructor. More...
 
std::string get_signature () const
 Returns the signature of this constructor as readable string. More...
 
variant invoke () const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
variant invoke (detail::argument arg1) const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
variant invoke (detail::argument arg1, detail::argument arg2) const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
variant invoke (detail::argument arg1, detail::argument arg2, detail::argument arg3) const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
variant invoke (detail::argument arg1, detail::argument arg2, detail::argument arg3, detail::argument arg4) const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
variant invoke (detail::argument arg1, detail::argument arg2, detail::argument arg3, detail::argument arg4, detail::argument arg5) const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
variant invoke (detail::argument arg1, detail::argument arg2, detail::argument arg3, detail::argument arg4, detail::argument arg5, detail::argument arg6) const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
variant invoke_variadic (std::vector< detail::argument > args) const
 Invokes the constructor of type returned by get_instanciated_type(). More...
 
bool is_valid () const
 Returns true if this constructor is valid, otherwise false. More...
 
 operator bool () const
 Convenience function to check if this constructor is valid or not. More...
 
bool operator!= (const constructor &other) const
 Returns true if this constructor is the not the same like the other. More...
 
bool operator== (const constructor &other) const
 Returns true if this constructor is the same like the other. More...
 

Detailed Description

The constructor class provides several meta information about a constructor and can be invoked.

A instance of a constructor class can only be obtained from the type class. See type::get_constructor() and type::get_constructors().

For registration a constructor, nested inside a class, see class_::constructor() and for global constructors see constructor_.

Meta Information

A constructor has a signature (get_signature()) and a instantiate exactly one type (get_instanciated_type()). With get_parameter_types() you retrieve all type objects of the parameters for this constructor. When the constructor was declared inside a class, then get_declaring_type() can be used to obtain the type of this class.

The method can be invoked with invoke(); When its not a static method you have to provide a class instance to invoke the method. This instance can be the raw type on the stack; the current hierarchy level doesn't matter. It can be also a raw pointer to the object or a variant which contains the instance, again as pointer or stack object.

Another way to invoke a method is to use the type class through type::create().

Copying and Assignment

A constructor object is lightweight and can be copied by value. However, each copy will refer to the same underlying constructor.

Typical Usage

constructor string_ctor == type::get("std::string").get_constructor({type::get("const char*")});
variant my_string = string_ctor.invoke({"Hello World"}); // returns an ptr to the object on the heap
std::cout << my_string.get_value<std::string*>()->c_str() << std::endl; // prints 'Hello World'
// don't forget to destroy the instance
type::get("std::string").get_destructor().invoke(my_string);
my_string.is_valid(); // yield to false
See also
method, property, enumeration, destructor and type

Member Function Documentation

type rttr::constructor::get_declaring_type ( ) const

Returns the type of the class or struct that declares this constructor.

Remarks
When this constructor does not belong to a class (i.e. is a primitive type) it will return an invalid type object. When this constructor is not valid, this function will return an invalid type object (see type::is_valid).
Returns
Type of the declaring class/struct for this enumeration.
type rttr::constructor::get_instanciated_type ( ) const

Returns the type object of the instantiated type.

Returns
The instantiated type.
variant rttr::constructor::get_metadata ( int  key) const

Returns the metadata for the given key key.

Remarks
When no metadata is registered with the given key, an invalid variant object is returned (see variant::is_valid).
Returns
A variant object, containing arbitrary data.
variant rttr::constructor::get_metadata ( const std::string &  key) const

Returns the metadata for the given key key.

Remarks
When no metadata is registered with the given key, an invalid variant object is returned (see variant::is_valid).
Returns
A variant object, containing arbitrary data.
std::vector<type> rttr::constructor::get_parameter_types ( ) const

Returns a list of type objects representing the number, order and type of the parameters for this constructor.

Returns
A list representing the parameters of this constructor.
std::string rttr::constructor::get_signature ( ) const

Returns the signature of this constructor as readable string.

Returns
The signature as readable string.
variant rttr::constructor::invoke ( ) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object.

Remarks
Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
variant rttr::constructor::invoke ( detail::argument  arg1) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object.

Remarks
Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
variant rttr::constructor::invoke ( detail::argument  arg1,
detail::argument  arg2 
) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object.

Remarks
Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
variant rttr::constructor::invoke ( detail::argument  arg1,
detail::argument  arg2,
detail::argument  arg3 
) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object.

Remarks
Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
variant rttr::constructor::invoke ( detail::argument  arg1,
detail::argument  arg2,
detail::argument  arg3,
detail::argument  arg4 
) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object.

Remarks
Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
variant rttr::constructor::invoke ( detail::argument  arg1,
detail::argument  arg2,
detail::argument  arg3,
detail::argument  arg4,
detail::argument  arg5 
) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object.

Remarks
Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
variant rttr::constructor::invoke ( detail::argument  arg1,
detail::argument  arg2,
detail::argument  arg3,
detail::argument  arg4,
detail::argument  arg5,
detail::argument  arg6 
) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object.

Remarks
Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
variant rttr::constructor::invoke_variadic ( std::vector< detail::argument >  args) const

Invokes the constructor of type returned by get_instanciated_type().

The instance will always be created on the heap and will be returned as variant object. Use this method when you need to instantiate a constructor with more then 6 parameters.

Remarks
Using this invoke function is slower, then specifying the arguments directly. Returns an invalid variant object (see variant::is_valid), when the arguments does not match the parameters of the underlying constructor.
Returns
An instance of the type get_instanciated_type().
bool rttr::constructor::is_valid ( ) const

Returns true if this constructor is valid, otherwise false.

Returns
True if this constructor is valid, otherwise false.
rttr::constructor::operator bool ( ) const

Convenience function to check if this constructor is valid or not.

Returns
True if this constructor is valid, otherwise false.
bool rttr::constructor::operator!= ( const constructor other) const

Returns true if this constructor is the not the same like the other.

Returns
True if both constructors are different, otherwise false.
bool rttr::constructor::operator== ( const constructor other) const

Returns true if this constructor is the same like the other.

Returns
True if both constructors are equal, otherwise false.

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