Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Friends | List of all members
Rice::Data_Type< T > Class Template Reference

A mechanism for binding ruby types to C++ types. More...

#include <Data_Type_defn.hpp>

Inheritance diagram for Rice::Data_Type< T >:
Rice::Module_impl< Data_Type_Base, Data_Type< T > > Rice::Data_Type_Base Rice::Module_impl< Class, Data_Type_Base > Rice::Class Rice::Module_impl< Module, Class > Rice::Module Rice::Module_impl< Module_base, Module > Rice::Module_base Rice::Object

Public Types

typedef T Type
 The C++ type being held.
 
- Public Types inherited from Rice::Data_Type_Base
typedef std::map< VALUE,
detail::Abstract_Caster * > 
Casters
 

Public Member Functions

 Data_Type ()
 Default constructor which does not bind. More...
 
 Data_Type (Module const &v)
 Constructor which takes a Module. More...
 
virtual ~Data_Type ()
 Destructor.
 
virtual Data_Typeoperator= (Module const &klass)
 Assignment operator which takes a Module. More...
 
template<typename Constructor_T >
Data_Type< T > & define_constructor (Constructor_T constructor, Arguments *arguments=0)
 Define a constructor for the class. More...
 
template<typename Constructor_T >
Data_Type< T > & define_constructor (Constructor_T constructor, Arg const &arg)
 
template<typename Director_T >
Data_Type< T > & define_director ()
 Register a Director class for this class. More...
 
virtual detail::Abstract_Caster * caster () const
 
- Public Member Functions inherited from Rice::Module_impl< Data_Type_Base, Data_Type< T > >
 Module_impl (T const &arg)
 
Data_Type< T > & add_handler (Functor_T functor)
 Define an exception handler. More...
 
Data_Type< T > & define_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define an instance method. More...
 
Data_Type< T > & define_method (Identifier name, Func_T func, Arg const &arg)
 
Data_Type< T > & define_singleton_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define a singleton method. More...
 
Data_Type< T > & define_singleton_method (Identifier name, Func_T func, Arg const &arg)
 
Data_Type< T > & define_module_function (Identifier name, Func_T func, Arguments *arguments=0)
 Define a module function. More...
 
Data_Type< T > & define_module_function (Identifier name, Func_T func, Arg const &arg)
 
Data_Type< T > & define_iterator (Iterator_T(T::*begin)(), Iterator_T(T::*end)(), Identifier name="each")
 Define an iterator. More...
 
Data_Type< T > & include_module (Module const &inc)
 Include a module. More...
 
Data_Type< 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...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
- Public Member Functions inherited from Rice::Data_Type_Base
 Data_Type_Base ()
 Default constructor.
 
 Data_Type_Base (VALUE v)
 Constructor.
 
virtual ~Data_Type_Base ()=0
 Destructor.
 
- Public Member Functions inherited from Rice::Module_impl< Class, Data_Type_Base >
 Module_impl (T const &arg)
 
Data_Type_Baseadd_handler (Functor_T functor)
 Define an exception handler. More...
 
Data_Type_Basedefine_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define an instance method. More...
 
Data_Type_Basedefine_method (Identifier name, Func_T func, Arg const &arg)
 
Data_Type_Basedefine_singleton_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define a singleton method. More...
 
Data_Type_Basedefine_singleton_method (Identifier name, Func_T func, Arg const &arg)
 
Data_Type_Basedefine_module_function (Identifier name, Func_T func, Arguments *arguments=0)
 Define a module function. More...
 
Data_Type_Basedefine_module_function (Identifier name, Func_T func, Arg const &arg)
 
Data_Type_Basedefine_iterator (Iterator_T(T::*begin)(), Iterator_T(T::*end)(), Identifier name="each")
 Define an iterator. More...
 
Data_Type_Baseinclude_module (Module const &inc)
 Include a module. More...
 
Data_Type_Baseconst_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...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
- Public Member Functions inherited from Rice::Class
 Class ()
 
 Class (VALUE v)
 Construct a new class wrapper from a ruby object of type T_CLASS.
 
Classundef_creation_funcs ()
 Disallow creation of an instance from Ruby code. More...
 
- Public Member Functions inherited from Rice::Module_impl< Module, Class >
 Module_impl (T const &arg)
 
Classadd_handler (Functor_T functor)
 Define an exception handler. More...
 
Classdefine_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define an instance method. More...
 
Classdefine_method (Identifier name, Func_T func, Arg const &arg)
 
Classdefine_singleton_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define a singleton method. More...
 
Classdefine_singleton_method (Identifier name, Func_T func, Arg const &arg)
 
Classdefine_module_function (Identifier name, Func_T func, Arguments *arguments=0)
 Define a module function. More...
 
Classdefine_module_function (Identifier name, Func_T func, Arg const &arg)
 
Classdefine_iterator (Iterator_T(T::*begin)(), Iterator_T(T::*end)(), Identifier name="each")
 Define an iterator. More...
 
Classinclude_module (Module const &inc)
 Include a module. More...
 
Classconst_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...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
- Public Member Functions inherited from Rice::Module
 Module ()
 Default construct a Module and initialize it to rb_cObject.
 
 Module (VALUE v)
 Construct a Module from an existing Module object.
 
String name () const
 Return the name of the module.
 
void swap (Module &other)
 Swap with another Module.
 
Array ancestors () const
 Return an array containing the Module's ancestors. More...
 
Class singleton_class () const
 Return the module's singleton class. More...
 
- Public Member Functions inherited from Rice::Module_impl< Module_base, Module >
 Module_impl (T const &arg)
 
Moduleadd_handler (Functor_T functor)
 Define an exception handler. More...
 
Moduledefine_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define an instance method. More...
 
Moduledefine_method (Identifier name, Func_T func, Arg const &arg)
 
Moduledefine_singleton_method (Identifier name, Func_T func, Arguments *arguments=0)
 Define a singleton method. More...
 
Moduledefine_singleton_method (Identifier name, Func_T func, Arg const &arg)
 
Moduledefine_module_function (Identifier name, Func_T func, Arguments *arguments=0)
 Define a module function. More...
 
Moduledefine_module_function (Identifier name, Func_T func, Arg const &arg)
 
Moduledefine_iterator (Iterator_T(T::*begin)(), Iterator_T(T::*end)(), Identifier name="each")
 Define an iterator. More...
 
Moduleinclude_module (Module const &inc)
 Include a module. More...
 
Moduleconst_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...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
Data_Type< T > define_class (char const *name)
 Define a new data class under this module. More...
 
- Public Member Functions inherited from Rice::Module_base
 Module_base (VALUE v=rb_cObject)
 
 Module_base (Module_base const &other)
 
Module_baseoperator= (Module_base const &other)
 
void swap (Module_base &other)
 
- Public Member Functions inherited from Rice::Object
 Object (VALUE value=Qnil)
 Encapsulate an existing ruby object.
 
 Object (Object const &other)
 Copy constructor.
 
virtual ~Object ()
 Destructor.
 
bool test () const
 
 operator bool () const
 
bool is_nil () const
 Returns true if the object is nil, false otherwise.
 
 operator VALUE () const
 Implicit conversion to VALUE.
 
VALUE const volatile & value () const
 Explicitly get the encapsulated VALUE.
 
Class class_of () const
 Get the class of an object. More...
 
int compare (Object const &other) const
 Compare this object to another object. More...
 
String to_s () const
 Return a string representation of an object. More...
 
String inspect () const
 Inspect the object. More...
 
void freeze ()
 Freeze the object.
 
bool is_frozen () const
 Determine if the object is frozen. More...
 
void swap (Object &other)
 Swap with another Object.
 
Object instance_eval (String const &s)
 Evaluate the given string in the context of the object. More...
 
int rb_type () const
 Return the type of the underlying C object. More...
 
bool is_a (Object klass) const
 Determine whether the object is an instance of a class/module. More...
 
bool respond_to (Identifier id) const
 Determine if the objects responds to a method. More...
 
bool is_instance_of (Object klass) const
 Determine whether class is the object's class. More...
 
template<typename T >
void iv_set (Identifier name, T const &value)
 Set an instance variable. More...
 
Object iv_get (Identifier name) const
 Get the value of an instance variable. More...
 
Object attr_get (Identifier name) const
 Get the value of an instance variable, but don't warn if it is. More...
 
template<typename Retval_T >
Retval_T call (Identifier id, T1 arg1, T2 arg2,...) const
 Call the Ruby method specified by 'id' on object 'obj'. More...
 
Object call (Identifier id, T1 arg1, T2 arg2,...) const
 Version of call which defaults to Object return type.
 
Object vcall (Identifier id, Array args)
 Vectorized call. More...
 
void mark () const
 Mark the object with the garbage collector.
 

Static Public Member Functions

static Module klass ()
 Explictly return the Ruby type. More...
 
static T * from_ruby (Object x)
 Convert ruby object x to type T. More...
 
static bool is_bound ()
 Determine if the type is bound. More...
 
- Static Public Member Functions inherited from Rice::Data_Type_Base
static Casters & casters ()
 

Static Public Attributes

static std::auto_ptr
< detail::Abstract_Caster > 
caster_
 

Static Protected Member Functions

template<typename Base_T >
static Data_Type bind (Module const &klass)
 Bind a Data_Type to a VALUE. More...
 

Friends

template<typename T_ >
class Data_Type
 
template<typename T_ >
Rice::Data_Type< T_ > define_class_under (Object module, char const *name)
 Define a new data class in the namespace given by module. More...
 
template<typename T_ , typename Base_T_ >
Rice::Data_Type< T_ > define_class_under (Object module, char const *name)
 Define a new data class in the namespace given by module. More...
 
template<typename T_ >
Rice::Data_Type< T_ > Rice::define_class (char const *name)
 
template<typename T_ , typename Base_T_ >
Rice::Data_Type< T_ > define_class (char const *name)
 Define a new data class in the default namespace. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Rice::Module_base
template<typename Exception_T , typename Functor_T >
void add_handler (Functor_T functor)
 
Object handler () const
 
- Protected Member Functions inherited from Rice::Object
void set_value (VALUE v)
 Set the encapsulated value.
 

Detailed Description

template<typename T>
class Rice::Data_Type< T >

A mechanism for binding ruby types to C++ types.

This class binds run-time types (Ruby VALUEs) to compile-time types (C++ types). The binding can occur only once.

Examples:
map/map.cpp.

Constructor & Destructor Documentation

template<typename T>
Rice::Data_Type< T >::Data_Type ( )

Default constructor which does not bind.

No member functions must be called on this Data_Type except bind, until the type is bound.

template<typename T>
Rice::Data_Type< T >::Data_Type ( Module const &  v)

Constructor which takes a Module.

Binds the type to the given VALUE according to the rules given above.

Parameters
klassthe module to which to bind.

Member Function Documentation

template<typename T>
template<typename Base_T >
static Data_Type Rice::Data_Type< T >::bind ( Module const &  klass)
staticprotected

Bind a Data_Type to a VALUE.

Throws an exception if the Data_Type is already bound to a different class. Any existing instances of the Data_Type will be bound after this function returns.

Parameters
klassthe ruby type to which to bind.
Returns
*this
template<typename T>
template<typename Constructor_T >
Data_Type<T>& Rice::Data_Type< T >::define_constructor ( Constructor_T  constructor,
Arguments *  arguments = 0 
)

Define a constructor for the class.

Creates a singleton method allocate and an instance method called initialize which together create a new instance of the class. The allocate method allocates memory for the object reference and the initialize method constructs the object.

Parameters
constructoran object that has a static member function construct() that constructs a new instance of T and sets the object's data member to point to the new instance. A helper class Constructor is provided that does precisely this. For example:
* define_class<Foo>("Foo")
* .define_constructor(Constructor<Foo>());
*
template<typename T>
template<typename Director_T >
Data_Type<T>& Rice::Data_Type< T >::define_director ( )

Register a Director class for this class.

For any class that uses Rice::Director to enable polymorphism across the languages, you need to register that director proxy class with this method. Not doing so will cause the resulting library to die at run time when it tries to convert the base type into the Director proxy type, and cannot find an appropriate Caster.

This method takes no arguments, just needs the type of the Director proxy class.

For example:

* class FooDirector : public Foo, public Rice::Director {
* ...
* };
*
* define_class<Foo>("Foo")
* .define_director<FooDirector>()
* .define_constructor(Constructor<FooDirector, Rice::Object>());
*
template<typename T>
static T* Rice::Data_Type< T >::from_ruby ( Object  x)
static

Convert ruby object x to type T.

Parameters
xthe object to convert.
Returns
the C++ object wrapped inside object x.
template<typename T>
static bool Rice::Data_Type< T >::is_bound ( )
static

Determine if the type is bound.

Returns
true if the object is bound, false otherwise.
template<typename T>
static Module Rice::Data_Type< T >::klass ( )
static

Explictly return the Ruby type.

Returns
the ruby class to which the type is bound.
template<typename T>
virtual Data_Type& Rice::Data_Type< T >::operator= ( Module const &  klass)
virtual

Assignment operator which takes a Module.

Parameters
klassmust be the class to which this data type is already bound.
Returns
*this

Friends And Related Function Documentation

template<typename T>
template<typename T_ , typename Base_T_ >
Rice::Data_Type<T_> define_class ( char const *  name)
friend

Define a new data class in the default namespace.

The class will have a base class of Object.

Parameters
Tthe C++ type of the wrapped class.
Returns
the new class.

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.
modulethe the Module in which to define the class.
Returns
the new class.
template<typename T>
template<typename T_ >
Rice::Data_Type<T_> define_class_under ( Object  module,
char const *  name 
)
friend

Define a new data class in the namespace given by module.

The class will have a base class of Object.

Parameters
Tthe C++ type of the wrapped class.
modulethe the Module in which to define the class.
Returns
the new class.

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.
modulethe the Module in which to define the class.
Returns
the new class.
template<typename T>
template<typename T_ , typename Base_T_ >
Rice::Data_Type<T_> define_class_under ( Object  module,
char const *  name 
)
friend

Define a new data class in the namespace given by module.

The class will have a base class of Object.

Parameters
Tthe C++ type of the wrapped class.
modulethe the Module in which to define the class.
Returns
the new class.

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.
modulethe the Module in which to define the class.
Returns
the new class.

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