Class: FFI::Type::Mapped

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

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

Parameters:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/ffi_c/MappedType.c', line 86

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");
    }

    TypedData_Get_Struct(self, MappedType, &mapped_type_data_type, m);
    RB_OBJ_WRITE(self, &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");
    }

    RB_OBJ_WRITE(self, &m->rbConverter, rbConverter);
    TypedData_Get_Struct(m->rbType, Type, &rbffi_type_data_type, m->type);
    m->base.ffiType = m->type->ffiType;

    rb_obj_freeze(self);

    return self;
}

Instance Method Details

#converterObject



180
181
182
183
184
185
186
187
# File 'ext/ffi_c/MappedType.c', line 180

static VALUE
mapped_converter(VALUE self)
{
    MappedType*m = NULL;
    TypedData_Get_Struct(self, MappedType, &mapped_type_data_type, m);

    return m->rbConverter;
}

#from_native(*args) ⇒ Object

Parameters:



171
172
173
174
175
176
177
178
# File 'ext/ffi_c/MappedType.c', line 171

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

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

#native_typeType

Get native type of mapped type.

Returns:



145
146
147
148
149
150
151
152
# File 'ext/ffi_c/MappedType.c', line 145

static VALUE
mapped_native_type(VALUE self)
{
    MappedType*m = NULL;
    TypedData_Get_Struct(self, MappedType, &mapped_type_data_type, m);

    return m->rbType;
}

#to_native(*args) ⇒ Object

Parameters:



158
159
160
161
162
163
164
165
# File 'ext/ffi_c/MappedType.c', line 158

static VALUE
mapped_to_native(int argc, VALUE* argv, VALUE self)
{
    MappedType*m = NULL;
    TypedData_Get_Struct(self, MappedType, &mapped_type_data_type, m);

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

#native_typeType

Get native type of mapped type.

Returns:



145
146
147
148
149
150
151
152
# File 'ext/ffi_c/MappedType.c', line 145

static VALUE
mapped_native_type(VALUE self)
{
    MappedType*m = NULL;
    TypedData_Get_Struct(self, MappedType, &mapped_type_data_type, m);

    return m->rbType;
}