Class: FFI::StructByReference
- Inherits:
-
Object
- Object
- FFI::StructByReference
- Defined in:
- ext/ffi_c/StructByReference.c,
ext/ffi_c/StructByReference.c
Overview
This class includes DataConverter module.
Direct Known Subclasses
Instance Method Summary collapse
-
#from_native(value, ctx) ⇒ Struct
Create a struct from content of memory
value. -
#initialize(struc_class) ⇒ self
constructor
A new instance of StructByReference.
-
#native_type ⇒ Class
Always get Type::POINTER.
-
#struct_class ⇒ Struct
Get
struct_class. -
#to_native(value, ctx) ⇒ AbstractMemory
Pointer on
value.
Constructor Details
#initialize(struc_class) ⇒ self
A new instance of StructByReference.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'ext/ffi_c/StructByReference.c', line 78 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; } |
Instance Method Details
#from_native(value, ctx) ⇒ Struct
Create a struct from content of memory value.
161 162 163 164 165 166 167 168 169 |
# File 'ext/ffi_c/StructByReference.c', line 161 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 ⇒ Class
Always get Type::POINTER.
120 121 122 123 124 |
# File 'ext/ffi_c/StructByReference.c', line 120 static VALUE sbr_native_type(VALUE self) { return rb_const_get(rbffi_TypeClass, rb_intern("POINTER")); } |
#struct_class ⇒ Struct
Get struct_class.
105 106 107 108 109 110 111 112 113 |
# File 'ext/ffi_c/StructByReference.c', line 105 static VALUE sbr_struct_class(VALUE self) { StructByReference* sbr; Data_Get_Struct(self, StructByReference, sbr); return sbr->rbStructClass; } |
#to_native(value, ctx) ⇒ AbstractMemory
Returns Pointer on value.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/ffi_c/StructByReference.c', line 132 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; } |