Class: FFI::StructByReference

### Home Classes Methods

### In Files

- ext/ffi_c/ffi.c

### Parent

Object

### Methods

- ::new
- #from_native
- #native_type
- #struct_class
- #to_native

### Files

- Makefile
- LICENSE
- compile
- configure
- depcomp
- stamp-vti
- install-sh
- libtool-version
- mdate-sh
- missing

### Class/Module Index

Quicksearch

- FFI
- FFI::AutoPointer
- FFI::AutoPointer::CallableReleaser
- FFI::AutoPointer::DefaultReleaser
- FFI::AutoPointer::Releaser
- FFI::ConstGenerator
- FFI::ConstGenerator::Constant
- FFI::Enum
- FFI::Enums
- FFI::Function
- FFI::FunctionType
- FFI::Generator
- FFI::Generator::Task
- FFI::IO
- FFI::LastError
- FFI::ManagedStruct
- FFI::MemoryPointer
- FFI::NativeType
- FFI::Platform
- FFI::PlatformError
- FFI::Pointer
- FFI::StrPtrConverter
- FFI::Struct
- FFI::Struct::InlineArray
- FFI::Struct::ManagedStructConverter
- FFI::StructByReference
- FFI::StructByValue
- FFI::StructGenerator
- FFI::StructGenerator::Field
- FFI::StructLayout
- FFI::StructLayout::Array
- FFI::StructLayout::Enum
- FFI::StructLayout::Field
- FFI::StructLayout::Function
- FFI::StructLayout::InnerStruct
- FFI::StructLayout::Mapped
- FFI::StructLayout::Number
- FFI::StructLayout::Pointer
- FFI::StructLayout::String
- FFI::StructLayoutBuilder
- FFI::Type
- FFI::Type::Builtin
- FFI::TypesGenerator
- FFI::Union
- FFI::VariadicInvoker

No matching classes.

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