In Files

Parent

FFI::StructByReference

This class includes {FFI::DataConverter} module.

Public Class Methods

initialize(struc_class) click to toggle source
@param [Struct] struct_calss
@return [self]
A new instance of StructByReference.
static VALUE
sbr_initialize(VALUE self, VALUE rbStructClass)
{
    StructByReference* sbr = NULL;
    
    if (!rb_class_inherited_p(rbStructClass, rbffi_StructClass)) {
        rb_raise(rb_eTypeError, "wrong type (expected subclass of FFI::Struct)");
    }

    Data_Get_Struct(self, StructByReference, sbr);
    sbr->rbStructClass = rbStructClass;
    
    return self;
}

Public Instance Methods

from_native(value, ctx) click to toggle source
@param [AbstractMemory] value
@param [nil] ctx
@return [Struct]
Create a struct from content of memory +value+.
static VALUE
sbr_from_native(VALUE self, VALUE value, VALUE ctx)
{
    StructByReference* sbr;

    Data_Get_Struct(self, StructByReference, sbr);

    return rb_class_new_instance(1, &value, sbr->rbStructClass);
}
native_type click to toggle source
@return [Class]
Always get {FFI::Type}::POINTER.
static VALUE
sbr_native_type(VALUE self)
{
    return rb_const_get(rbffi_TypeClass, rb_intern("POINTER"));
}
struct_class click to toggle source
@return [Struct]
Get +struct_class+.
static VALUE
sbr_struct_class(VALUE self)
{
    StructByReference* sbr;

    Data_Get_Struct(self, StructByReference, sbr);

    return sbr->rbStructClass;
}
to_native(value, ctx) click to toggle source
@param [nil, Struct] value
@param [nil] ctx
@return [AbstractMemory] Pointer on +value+.
static VALUE
sbr_to_native(VALUE self, VALUE value, VALUE ctx)
{
    StructByReference* sbr;
    Struct* s;

    if (unlikely(value == Qnil)) {
        return rbffi_NullPointerSingleton;
    }

    Data_Get_Struct(self, StructByReference, sbr);
    if (!rb_obj_is_kind_of(value, sbr->rbStructClass)) {
        rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
                rb_obj_classname(value),
                RSTRING_PTR(rb_class_name(sbr->rbStructClass)));
    }

    Data_Get_Struct(value, Struct, s);

    return s->rbPointer;
}

[Validate]

Generated with the Darkfish Rdoc Generator 2.