Class: FFI::Type::Mapped

Inherits:
FFI::Type show all
Defined in:
ext/ffi_c/MappedType.c

Constant Summary

Constant Summary

Constants inherited from FFI::Type

Struct

Instance Method Summary collapse

Methods inherited from FFI::Type

#alignment, #inspect, #size

Constructor Details

#initialize(converter) ⇒ self



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/ffi_c/MappedType.c', line 68

static VALUE
mapped_initialize(VALUE self, VALUE rbConverter)
{
    MappedType* m = NULL;
    
    if (!rb_respond_to(rbConverter, id_native_type)) {
        rb_raise(rb_eNoMethodError, "native_type method not implemented");
    }

    if (!rb_respond_to(rbConverter, id_to_native)) {
        rb_raise(rb_eNoMethodError, "to_native method not implemented");
    }

    if (!rb_respond_to(rbConverter, id_from_native)) {
        rb_raise(rb_eNoMethodError, "from_native method not implemented");
    }
    
    Data_Get_Struct(self, MappedType, m);
    m->rbType = rb_funcall2(rbConverter, id_native_type, 0, NULL);
    if (!(rb_obj_is_kind_of(m->rbType, rbffi_TypeClass))) {
        rb_raise(rb_eTypeError, "native_type did not return instance of FFI::Type");
    }

    m->rbConverter = rbConverter;
    Data_Get_Struct(m->rbType, Type, m->type);
    m->base.ffiType = m->type->ffiType;
    
    return self;
}

Instance Method Details

#from_native(*args) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'ext/ffi_c/MappedType.c', line 137

static VALUE
mapped_from_native(int argc, VALUE* argv, VALUE self)
{
    MappedType*m = NULL;
    
    Data_Get_Struct(self, MappedType, m);

    return rb_funcall2(m->rbConverter, id_from_native, argc, argv);
}

#native_typeType

Get native type of mapped type.



110
111
112
113
114
115
116
117
# File 'ext/ffi_c/MappedType.c', line 110

static VALUE
mapped_native_type(VALUE self)
{
    MappedType*m = NULL;
    Data_Get_Struct(self, MappedType, m);

    return m->rbType;
}

#to_native(*args) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'ext/ffi_c/MappedType.c', line 123

static VALUE
mapped_to_native(int argc, VALUE* argv, VALUE self)
{
    MappedType*m = NULL;
    
    Data_Get_Struct(self, MappedType, m);
    
    return rb_funcall2(m->rbConverter, id_to_native, argc, argv);
}

#native_typeType

Get native type of mapped type.



110
111
112
113
114
115
116
117
# File 'ext/ffi_c/MappedType.c', line 110

static VALUE
mapped_native_type(VALUE self)
{
    MappedType*m = NULL;
    Data_Get_Struct(self, MappedType, m);

    return m->rbType;
}