Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Public Member Functions | List of all members
Rice::Module_impl< Base_T, Derived_T > Class Template Reference

#include <Module_impl.hpp>

Inheritance diagram for Rice::Module_impl< Base_T, Derived_T >:
Rice::Data_Type< Enum_T > Rice::Module_impl< Data_Type< Enum_T >, Enum< Enum_T, Enum_Traits > > Rice::Enum< Enum_T, Enum_Traits >

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

Detailed Description

template<typename Base_T, typename Derived_T>
class Rice::Module_impl< Base_T, Derived_T >

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.

Member Function Documentation

template<typename Base_T, typename Derived_T>
template<typename Exception_T , typename Functor_T >
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.

Parameters
Exception_Ta template parameter indicating the type of exception to be translated.
functora 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);
* }
*
template<typename Base_T, typename Derived_T>
bool Rice::Module_impl< Base_T, Derived_T >::const_defined ( Identifier  name) const

Determine whether a constant is defined.

Parameters
namethe name of the constant to check.
Returns
true if the constant is defined in this module or false otherwise.
template<typename Base_T, typename Derived_T>
Object Rice::Module_impl< Base_T, Derived_T >::const_get ( Identifier  name) const

Get a constant.

Parameters
namethe name of the constant to get.
Returns
the value of the constant.
template<typename Base_T, typename Derived_T>
Derived_T& Rice::Module_impl< Base_T, Derived_T >::const_set ( Identifier  name,
Object  value 
)

Set a constant.

Parameters
namethe name of the constant to set.
valuethe value of the constant.
Returns
*this
template<typename Base_T, typename Derived_T>
Class Rice::Module_impl< Base_T, Derived_T >::define_class ( char const *  name,
Object  superclass = rb_cObject 
)

Define a class under this module.

Parameters
namethe name of the class.
superclassthe base class to use.
Returns
the new class.
template<typename Base_T, typename Derived_T>
template<typename T >
Data_Type<T> Rice::Module_impl< Base_T, Derived_T >::define_class ( char const *  name)
inline

Define a new data class under this module.

The class will have a base class of Object.

Parameters
Tthe C++ type of the wrapped class.
Returns
the new class.
template<typename Base_T, typename Derived_T>
template<typename T , typename T_Base_T >
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<>.

Parameters
Tthe C++ type of the wrapped class.
Returns
the new class.
template<typename Base_T, typename Derived_T>
template<typename T , typename Iterator_T >
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.

Parameters
begina member function pointer to a function that returns an iterator to the beginning of the sequence.
enda member function pointer to a function that returns an iterator to the end of the sequence.
namethe name of the iterator.
Returns
*this
template<typename Base_T, typename Derived_T>
template<typename Func_T >
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().

Parameters
namethe name of the method
functhe implementation of the function, either a function pointer or a member function pointer.
argumentsthe list of arguments of this function, used for defining default parameters (optional)
Returns
*this
template<typename Base_T, typename Derived_T>
Module Rice::Module_impl< Base_T, Derived_T >::define_module ( char const *  name)

Define a module under this module.

Parameters
namethe name of the module.
Returns
the new class.
template<typename Base_T, typename Derived_T>
template<typename Func_T >
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().

Parameters
namethe name of the method
functhe implementation of the function, either a function pointer or a member function pointer.
argumentsthe list of arguments of this function, used for defining default parameters (optional)
Returns
*this
template<typename Base_T, typename Derived_T>
template<typename Func_T >
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().

Parameters
namethe name of the method
functhe implementation of the function, either a function pointer or a member function pointer.
argumentsthe list of arguments of this function, used for defining default parameters (optional)
Returns
*this
template<typename Base_T, typename Derived_T>
Derived_T& Rice::Module_impl< Base_T, Derived_T >::include_module ( Module const &  inc)

Include a module.

Parameters
incthe module to be included.
Returns
*this
template<typename Base_T, typename Derived_T>
void Rice::Module_impl< Base_T, Derived_T >::remove_const ( Identifier  name)

Remove a constant.

Parameters
namethe name of the constant to remove.

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