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

A smartpointer-like wrapper for Ruby data objects. More...

#include <Data_Object_defn.hpp>

Inheritance diagram for Rice::Data_Object< T >:
Rice::Object

Public Types

typedef void(* Ruby_Data_Func )(T *obj)
 A function that takes a T* and returns void.
 

Public Member Functions

 Data_Object (T *obj, VALUE klass=Data_Type< T >::klass(), Ruby_Data_Func mark_func=Default_Mark_Function< T >::mark, Ruby_Data_Func free_func=Default_Free_Function< T >::free)
 Wrap a C++ object. More...
 
 Data_Object (Object value)
 Unwrap a Ruby object. More...
 
template<typename U >
 Data_Object (Object value, Data_Type< U > const &klass=Data_Type< T >::klass())
 Unwrap a Ruby object. More...
 
 Data_Object (Data_Object const &other)
 Make a copy of a Data_Object. More...
 
T & operator* () const
 Return a reference to obj_.
 
T * operator-> () const
 Return a pointer to obj_.
 
T * get () const
 Return a pointer to obj_.
 
template<typename U >
void swap (Data_Object< U > &ref)
 Swap with another data object of the same type. More...
 
- 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.
 

Additional Inherited Members

- Protected Member Functions inherited from Rice::Object
void set_value (VALUE v)
 Set the encapsulated value.
 

Detailed Description

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

A smartpointer-like wrapper for Ruby data objects.

A data object is a ruby object of type T_DATA, which is usually created by using the Data_Wrap_Struct or Data_Make_Struct macro. This class wraps creation of the data structure, providing a type-safe object-oriented interface to the underlying C interface. This class works in conjunction with the Data_Type class to ensure type safety.

Example:

* class Foo { };
* ...
* Data_Type<Foo> rb_cFoo = define_class("Foo");
* ...
* // Wrap:
* Data_Object<Foo> foo1(new Foo);
*
* // Get value to return:
* VALUE v = foo1.value()
*
* // Unwrap:
* Data_Object<Foo> foo2(v, rb_cFoo);
*
Examples:
enum/sample_enum.cpp.

Constructor & Destructor Documentation

template<typename T>
Rice::Data_Object< T >::Data_Object ( T *  obj,
VALUE  klass = Data_Type< T >::klass(),
Ruby_Data_Func  mark_func = Default_Mark_Function< T >::mark,
Ruby_Data_Func  free_func = Default_Free_Function< T >::free 
)

Wrap a C++ object.

This constructor is analgous to calling Data_Wrap_Struct. Be careful not to call this function more than once for the same pointer (in general, it should only be called for newly constructed objects that need to be managed by Ruby's garbage collector).

Parameters
objthe object to wrap.
klassthe Ruby class to use for the newly created Ruby object.
mark_funca function that gets called by the garbage collector to mark the object's children.
free_funca function that gets called by the garbage collector to free the object.
template<typename T>
Rice::Data_Object< T >::Data_Object ( Object  value)

Unwrap a Ruby object.

This constructor is analgous to calling Data_Get_Struct. Uses Data_Type<T>::klass as the class of the object.

Parameters
valuethe Ruby object to unwrap.
template<typename T>
template<typename U >
Rice::Data_Object< T >::Data_Object ( Object  value,
Data_Type< U > const &  klass = Data_Type< T >::klass() 
)

Unwrap a Ruby object.

This constructor is analgous to calling Data_Get_Struct. Will throw an exception if the class of the object differs from the specified class.

Parameters
valuethe Ruby object to unwrap.
klassthe expected class of the object.
template<typename T>
Rice::Data_Object< T >::Data_Object ( Data_Object< T > const &  other)

Make a copy of a Data_Object.

Parameters
otherthe Data_Object to copy.

Member Function Documentation

template<typename T>
template<typename U >
void Rice::Data_Object< T >::swap ( Data_Object< U > &  ref)

Swap with another data object of the same type.

Parameters
refthe object with which to swap.

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