Rice
3.0.0
|
#include <Module_impl.hpp>
Public Member Functions | |
template<typename T > | |
Module_impl (T const &arg) | |
template<typename Exception_T , typename Functor_T > | |
Derived_T & | add_handler (Functor_T functor) |
Define an exception handler. More... | |
template<typename Func_T > | |
Derived_T & | define_method (Identifier name, Func_T func, Arguments *arguments=0) |
Define an instance method. More... | |
template<typename Func_T > | |
Derived_T & | define_method (Identifier name, Func_T func, Arg const &arg) |
template<typename Func_T > | |
Derived_T & | define_singleton_method (Identifier name, Func_T func, Arguments *arguments=0) |
Define a singleton method. More... | |
template<typename Func_T > | |
Derived_T & | define_singleton_method (Identifier name, Func_T func, Arg const &arg) |
template<typename Func_T > | |
Derived_T & | define_module_function (Identifier name, Func_T func, Arguments *arguments=0) |
Define a module function. More... | |
template<typename Func_T > | |
Derived_T & | define_module_function (Identifier name, Func_T func, Arg const &arg) |
template<typename T , typename Iterator_T > | |
Derived_T & | define_iterator (Iterator_T(T::*begin)(), Iterator_T(T::*end)(), Identifier name="each") |
Define an iterator. More... | |
Derived_T & | include_module (Module const &inc) |
Include a module. More... | |
Derived_T & | const_set (Identifier name, Object value) |
Set a constant. More... | |
Object | const_get (Identifier name) const |
Get a constant. More... | |
bool | const_defined (Identifier name) const |
Determine whether a constant is defined. More... | |
void | remove_const (Identifier name) |
Remove a constant. More... | |
Module | define_module (char const *name) |
Define a module under this module. More... | |
Class | define_class (char const *name, Object superclass=rb_cObject) |
Define a class under this module. More... | |
template<typename T > | |
Data_Type< T > | define_class (char const *name) |
Define a new data class under this module. More... | |
template<typename T , typename T_Base_T > | |
Data_Type< T > | define_class (char const *name) |
Define a new data class under this module. More... | |
An intermediate base class so we can always return the most-derived type (Module, Class, Data_Type, ...) without having to re-implement each function for each derived class.
Derived_T& Rice::Module_impl< Base_T, Derived_T >::add_handler | ( | Functor_T | functor | ) |
Define an exception handler.
Whenever an exception of type Exception_T is thrown from a function defined on this class, functor will be called to translate the exception into a ruby exception.
Exception_T | a template parameter indicating the type of exception to be translated. |
functor | a functor to be called to translate the exception into a ruby exception. This functor should re-throw the exception as an Exception. Example: class MyException : public std::exception { };
Data_Type<MyException> rb_cMyException;
Class rb_cFoo;
void translate_my_exception(MyException const & ex)
{
Data_Object<MyException> ex_(
new MyException(ex),
rb_cMyException);
throw Exception(ex_);
}
extern "C"
void Init_MyExtension()
{
rb_cMyException = define_class("MyException");
rb_cFoo = define_class("Foo")
.add_handler<MyException>(translate_my_exception);
}
Class define_class(char const *name, Object superclass=rb_cObject) Define a class under this module. Derived_T & add_handler(Functor_T functor) Define an exception handler. |
bool Rice::Module_impl< Base_T, Derived_T >::const_defined | ( | Identifier | name | ) | const |
Determine whether a constant is defined.
name | the name of the constant to check. |
Object Rice::Module_impl< Base_T, Derived_T >::const_get | ( | Identifier | name | ) | const |
Get a constant.
name | the name of the constant to get. |
Derived_T& Rice::Module_impl< Base_T, Derived_T >::const_set | ( | Identifier | name, |
Object | value | ||
) |
Set a constant.
name | the name of the constant to set. |
value | the value of the constant. |
|
inline |
Define a new data class under this module.
The class will have a base class of Object.
T | the C++ type of the wrapped class. |
Data_Type<T> Rice::Module_impl< Base_T, Derived_T >::define_class | ( | char const * | name | ) |
Define a new data class under this module.
The class with have a base class determined by Base_T (specifically, Data_Type<Base_T>::klass). Therefore, the type Base_T must already have been registered using define_class<> or define_class_under<>.
T | the C++ type of the wrapped class. |
Class Rice::Module_impl< Base_T, Derived_T >::define_class | ( | char const * | name, |
Object | superclass = rb_cObject |
||
) |
Define a class under this module.
name | the name of the class. |
superclass | the base class to use. |
Derived_T& Rice::Module_impl< Base_T, Derived_T >::define_iterator | ( | Iterator_T(T::*)() | begin, |
Iterator_T(T::*)() | end, | ||
Identifier | name = "each" |
||
) |
Define an iterator.
Essentially this is a conversion from a C++-style begin/end iterator to a Ruby-style #each iterator.
begin | a member function pointer to a function that returns an iterator to the beginning of the sequence. |
end | a member function pointer to a function that returns an iterator to the end of the sequence. |
name | the name of the iterator. |
Derived_T& Rice::Module_impl< Base_T, Derived_T >::define_method | ( | Identifier | name, |
Func_T | func, | ||
Arguments * | arguments = 0 |
||
) |
Define an instance method.
The method's implementation can be any function or member function. A wrapper will be generated which will use from_ruby<> to convert the arguments from ruby types to C++ types before calling the function. The return value will be converted back to ruby by using to_ruby().
name | the name of the method |
func | the implementation of the function, either a function pointer or a member function pointer. |
arguments | the list of arguments of this function, used for defining default parameters (optional) |
Module Rice::Module_impl< Base_T, Derived_T >::define_module | ( | char const * | name | ) |
Define a module under this module.
name | the name of the module. |
Derived_T& Rice::Module_impl< Base_T, Derived_T >::define_module_function | ( | Identifier | name, |
Func_T | func, | ||
Arguments * | arguments = 0 |
||
) |
Define a module function.
A module function is a function that can be accessed either as a singleton method or as an instance method. The method's implementation can be any function or member function. A wrapper will be generated which will use from_ruby<> to convert the arguments from ruby types to C++ types before calling the function. The return value will be converted back to ruby by using to_ruby().
name | the name of the method |
func | the implementation of the function, either a function pointer or a member function pointer. |
arguments | the list of arguments of this function, used for defining default parameters (optional) |
Derived_T& Rice::Module_impl< Base_T, Derived_T >::define_singleton_method | ( | Identifier | name, |
Func_T | func, | ||
Arguments * | arguments = 0 |
||
) |
Define a singleton method.
The method's implementation can be any function or member function. A wrapper will be generated which will use from_ruby<> to convert the arguments from ruby types to C++ types before calling the function. The return value will be converted back to ruby by using to_ruby().
name | the name of the method |
func | the implementation of the function, either a function pointer or a member function pointer. |
arguments | the list of arguments of this function, used for defining default parameters (optional) |
Derived_T& Rice::Module_impl< Base_T, Derived_T >::include_module | ( | Module const & | inc | ) |
Include a module.
inc | the module to be included. |
void Rice::Module_impl< Base_T, Derived_T >::remove_const | ( | Identifier | name | ) |
Remove a constant.
name | the name of the constant to remove. |